服务器获取客户端信息的代码大致如下
InputStream is = socket.getInputStream();
byte[] buffer = new byte[1024];
int length = is.read(buffer);
String msg = new String(buffer,0,length);
为什么以下的写法是错误的
InputStream is = socket.getInputStream();
byte[] buffer = new byte[1024];
int length = 0;
while((length = is.read(buffer)) != -1){
String msg = new String(buffer,0,length);
}
------解决方案--------------------
我之前这样也不行,不知道是为什么!等待求解啊!!!