客户端读不到数据??一直处于阻塞状态...问题在服务器端还是客户端?
服务器端发送数据:
Iterator<SocketChannel> it=clients.iterator();
System.out.println(clients.size());
while(it.hasNext()){
SocketChannel channel=it.next();
System.out.println("send message to"+channel.socket().getInetAddress()+":"+content.toString());
channel.write(ByteBuffer.allocate(content.length()+2).put((content.toString()+"\r\n").getBytes()));
}
客户端读数据:
注意:客户端是使用的Socket,服务器使用的是Channel
public void run() {
BufferedReader br = null;
try {
br = new BufferedReader(new InputStreamReader(
socket.getInputStream()));
while (!stop) {
System.out.println(br.readLine());
System.out.println("end");
}
} catch (IOException e) {
e.printStackTrace();
} finally {
Resources.close(br);
}
}