Have you solved the TCP sticky problem? Since it is TCP, we have to consider 粘包的问题。粘包If the problem is not solved, you will not be able to determine which bytes are the first 4 bytes of a packet.
In short, you receive a lot of bytes, and the source of these bytes may be as follows:
Send all the bytes of two or three packets together
The second half of the previous packet and the first half of the bytes of the next packet are sent together
In short, it’s a mixture of half packs or sticky packs
We use netty,tcp粘包的问题,这里有一个很好阐述和基于netty’s solution: https://my.oschina.net/andylu...
This is a socket communication header problem. This is how I handled it in my previous project. The code snippet is as follows:
send(String url, int port, String content){
Socket socket = null;
OutputStream out = null;
DataOutputStream dataOutputStream = null;
try {
socket = new Socket(url, port);
out = socket.getOutputStream();
dataOutputStream = new DataOutputStream(out);
dataOutputStream.writeInt(content.getBytes().length);
dataOutputStream.write(content.getBytes());
dataOutputStream.flush();
...
}
}
It is recommended to write a receiving socket for debugging. I have never used the packet capture tool. Or you can jointly debug with the other party. If the other party can receive and successfully parse it, it will be OK. There is no need to get into trouble with the packet capture. Hope it can help you~
Have you solved the TCP sticky problem?
Since it is TCP, we have to consider
粘包
的问题。粘包
If the problem is not solved, you will not be able to determine which bytes are the first 4 bytes of a packet.In short, you receive a lot of bytes, and the source of these bytes may be as follows:
Send all the bytes of two or three packets together
The second half of the previous packet and the first half of the bytes of the next packet are sent together
In short, it’s a mixture of half packs or sticky packs
We use
netty
,tcp粘包的问题,这里有一个很好阐述和基于netty
’s solution: https://my.oschina.net/andylu...What does it mean to read the input stream directly in Java without capturing the packet?
This is a socket communication header problem. This is how I handled it in my previous project. The code snippet is as follows:
It is recommended to write a receiving socket for debugging. I have never used the packet capture tool. Or you can jointly debug with the other party. If the other party can receive and successfully parse it, it will be OK. There is no need to get into trouble with the packet capture.
Hope it can help you~
Have you called flush?