中级会员
 
- 积分
- 230
- 金钱
- 230
- 注册时间
- 2017-1-2
- 在线时间
- 31 小时
|
1金钱
如题写了一个tcp sever的发送和接收。发现接收不到。于是用网络调试助手测试,建立 client连接后,sever接收不到数据。不知道是不是接收要有固定格式?
程序如下
public static void main(String[] args) {
try{
ServerSocket ss = new ServerSocket(5566);
Socket client = ss.accept();
DataInputStream inFromClient = new DataInputStream(client.getInputStream());
DataOutputStream outTOClient = new DataOutputStream(client.getOutputStream());
String str;
double radius, area;
boolean flag = true;
while(flag) {
str = inFromClient.readUTF();
if(!"bye".equals(str)){
radius = Double.parseDouble(str);
System.out.println("收到的客户端数据:" + radius);
outTOClient.writeUTF(str);
outTOClient.flush();
System.out.println("str:" + str +"已经发送到客户端");
}else {
flag = false;
outTOClient.writeUTF("bye");
outTOClient.flush();
}
}
inFromClient.close();
outTOClient.close();
ss.close();
}catch(IOException e) {
e.printStackTrace();
}
}
|
|