我正在尝试使用德州仪器(TI)的助推器包cc3000发送数据。因此我在我的主板上实现了一个TCP服务器套接字。我可以成功接受挂起的连接,并在给定的套接字上发送和接收数据。在我的协议中,客户端负责在读取响应后关闭连接。但是在一些传输之后传输变得缓慢。如果我使用Wireshark检查WLAN流量,我发现套接字关闭过程有问题。我的客户端是基于java的程序。该板使用地址100,计算机在102下运行。
TCP流看起来如下:
31 4.696711000 192.168.2.102 192.168.2.100 TCP 66 50721 > http-alt [SYN] Seq=0 Win=8192 Len=0 MSS=1460 WS=4 SACK_PERM=1
32 4.700359000 192.168.2.100 192.168.2.102 TCP 58 http-alt > 50721 [SYN, ACK] Seq=0 Ack=1 Win=1460 Len=0 MSS=1460
33 4.700394000 192.168.2.102 192.168.2.100 TCP 54 50721 > http-alt [ACK] Seq=1 Ack=1 Win=17520 Len=0
34 4.700461000 192.168.2.102 192.168.2.100 HTTP 55 Continuation or non-HTTP traffic
35 4.705454000 192.168.2.100 192.168.2.102 TCP 54 http-alt > 50721 [ACK] Seq=1 Ack=2 Win=1460 Len=0
36 4.705476000 192.168.2.102 192.168.2.100 TCP 57 [TCP segment of a reassembled PDU]
37 4.709035000 192.168.2.100 192.168.2.102 TCP 54 http-alt > 50721 [ACK] Seq=1 Ack=5 Win=1460 Len=0
38 5.194961000 192.168.2.100 192.168.2.102 TCP 58 [TCP segment of a reassembled PDU]
39 5.196220000 192.168.2.100 192.168.2.102 HTTP 154 Continuation or non-HTTP traffic
40 5.196244000 192.168.2.102 192.168.2.100 TCP 54 50721 > http-alt [ACK] Seq=5 Ack=105 Win=17416 Len=0
41 5.196286000 192.168.2.102 192.168.2.100 TCP 54 50721 > http-alt [FIN, ACK] Seq=5 Ack=105 Win=17416 Len=0
42 5.202194000 192.168.2.100 192.168.2.102 TCP 54 http-alt > 50721 [ACK] Seq=105 Ack=6 Win=1460 Len=0
138 24.245036000 192.168.2.100 192.168.2.102 TCP 54 http-alt > 50721 [FIN, ACK] Seq=105 Ack=6 Win=1460 Len=0
139 24.245060000 192.168.2.102 192.168.2.100 TCP 54 50721 > http-alt [ACK] Seq=6 Ack=106 Win=17416 Len=0
在大约10次传输后,我得到了FIN / ACK级联。上面的最后一个FIN / ACK是这个级联的一部分。看起来套接字没有完全关闭,HW模块现在开始关闭一行中的所有套接字。
My Java - client does the following
Socket b = new Socket("192.168.2.100",8080);
OutputStream o = b.getOutputStream();
o.write(10);
o.write(0);
o.write(0);
o.write(0);
o.flush();
InputStream i = b.getInputStream();
int id = i.read();
int gId = i.read();
int lengthA = i.read();
int lengthB = i.read();
int length = (lengthB<<8)|lengthA;
if(length < 0|| length > 1000)
{
b.close();
return;
}
System.out.println(new Date()+" GantryID: "+gId+" Package with id: "+id+" has length: "+length+" payload: ");
DataInputStream ds = new DataInputStream(i);
byte[] buffer = new byte[length];
ds.readFully(buffer);
b.close();
System.out.println(new String(buffer));
服务器稍微复杂一些,但重要的命令是:
return recv(handle, data, size, 0); //Read request header
return recv(handle, data, size, 0); //Read request payload
send(handle, data, size, 0); //Write response header
send(handle, data, size, 0); //Write response payload
//No Close only set socket handle to -1
有没有人知道发生了什么。我将不胜感激任何帮助和想法。