![]() |
|
|
#1 |
|
Архивный участник
Join Date: Nov 2006
Posts: 13
|
I noticed somthing strange and cant find any explanation for that ...
Game server some times send 2 game packets in 1 TCP packet and that is ok but look at the packet below: ================= START Enqueue ================ 0 1 2 3 4 5 6 7 8 9 A B C D E F -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 0000 03 00 94 17 00 FB CE CE CE 6F 03 57 D0 28 1D 1D .........o.W.(.. 0010 1D BC D0 84 03 FB 49 07 B3 64 ......I..d ================= END Enqueue ================== from that we have First game Packet Len 3 Bytes Packet Data 0x94 (Packet ID 0x63 == Request Quest List) Second Game Packet Len 17 Pacet ID ID 0x03 == EnterWorld Total Bytes should be 3+17=20 Then what the hell is last 6 bytes 03 FB 49 07 B3 64 If that is a checksum whey the previus packet dont have checksum at the end like this one : ================= START Enqueue ================ 0 1 2 3 4 5 6 7 8 9 A B C D E F -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 0000 07 00 FF CA CA CA 6B ......k ================= END Enqueue ================== Or maybe is a first part of incomplete game packet that will come in next TCP packet but then len of that packet should be 64259 and that is imposible |
|
|
|
|
#2 |
|
Архивный участник
Join Date: Apr 2006
Posts: 461
|
TCP is a streaming protocol, lol. That's why you send len in the packet and read only len bytes for each packet.
There is no error.... |
|
|
|
|
#3 |
|
Архивный участник
Join Date: Nov 2006
Posts: 13
|
i am not using network straming i am using async sockets and reading all the data that client sends put in a byte queue then check packet priority a dequeue .. nvm i am idiot len of the second packet is not 17 ists 23 .. i was too sleepy
tnx anyway |
|
|
|
|
#4 |
|
Архивный участник
Join Date: Apr 2006
Posts: 461
|
TCP is a Streaming Protocol, please go read what that means. It doesn't matter if you use Sync or Async sockets, the TCP packets will come at you in order, but they will have no packet breaks. In essence, you will get one giant, never-ending stream of bytes. This is why you have to read the len from the packet and only read len bytes. Otherwise, you will never know where the start and end of a packet are.
I did socket programming in C++ using TCP, so I'm not talking up a storm without experience. |
|
|
|
|
#5 | |
|
Архивный участник
Join Date: Nov 2006
Posts: 13
|
Quote:
its depends how you are using the sockets In example in C if you are using int recv(int sockfd, void *buf, int len, unsigned int flags); return value is how much data (bytes ) actualy comes to that socket and now here is the "Solved" question recv recived 26 bytes of data and in this 26 bytes we have 2 game packets. |
|
|
|
|
|
#6 |
|
Архивный участник
Join Date: Jan 2006
Posts: 281
|
but in general mcrab is right tcp is always a stream dude...
|
|
|
|
|
#7 | |||
|
Архивный участник
Join Date: Apr 2006
Posts: 461
|
From Wikipedia under Transmission Control Protocol:
Quote:
Quote:
TCP is a stream protocol because it makes sure you get all the packet data in order, on the same socket, with reliability. It does not break the stream up in any way. If you send 5600 bytes in 2 seconds and go to do a socket read, you will get 5600 bytes of data. This could be 1, 2, 500 packets. TCP does not care, because it only handles the stream. That's why it is up to you to read properly. I'll show you some example C++ Winsock Receive code: Quote:
Sorry if I came across as trying to be rude or something, but you were wrong and I had to try to explain to you the difference between a stream and packet protocol. |
|||
|
|
| Thread Tools | Search this Thread |
| Display Modes | |
|
|