我创建了一个DataInputStream后却无法接受数据这是为什么呢
package Server;
import Chat.ChatThread;
import Chat.ManageClientThread;
import Chat.Message;
import Information.Commodity;
import java.io.*;
import java.net.ServerSocket;
import java.net.Socket;
import java.sql.SQLException;
public class ChatServer {
private Socket client;
private DataInputStream dis;
private DataOutputStream dos;
public ChatServer(Socket client) throws IOException {
this.client=client;
dis = new DataInputStream(client.getInputStream());
dos=new DataOutputStream(client.getOutputStream());
}
//接受数据
private String receive() {
String datas= null;
try {
datas = dis.readUTF();
} catch (IOException e) {
e.printStackTrace();
}
return datas;
}
//发送数据
private void send(String msg) {
try {
dos.writeUTF(msg);
dos.flush();
} catch (IOException e) {
e.printStackTrace();
}
}
//sendint
private void sendInt(int i) throws IOException {
dos.writeInt(i);
dos.flush();
}
//释放资源
private void release(){
try {
dis.close();
dos.close();
client.close();
} catch (IOException e) {
e.printStackTrace();
}
}
public static void main(String[] args) throws IOException, ClassNotFoundException {
ServerSocket server=new ServerSocket(10086);
boolean flag=true;
while(flag){
Socket client = server.accept();
System.out.println("一个客户端链接");
//一个客户端链
ChatServer cs=new ChatServer(client);
**String sender=cs.receive();
//在这里无法接受,这到底是为什么呢?**
//这里单开一个线程,让此线程与服务器端保持联系
ChatThread chatThread=new ChatThread(client);
new Thread(chatThread).start();
System.out.println("new Threead begin");
ManageClientThread.addClientThread(sender,chatThread);
}
}
}