TCP protocol data packets

Category: VC/MFC -> Network Author: qdronghh Date: 2001-09-16 02:43:37
2001-09-16 02:43:37
For example, the server sends a data packet to the client.
packet is the structure ( synchronization header ( 2 bytes ) , the function code ( 1 byte ) , feature data ( 1 ) , data length (n), the data field (n), check code ( 2 ) , end code (2))
client according to the function code to execute different modules, ask how to code structure is more reasonable ? Packet is sent using TCP protocol.
2001-09-16 03:10:30
send a good run , the most critical issue is to see how you points off the packet , I suggest you put a complete data packet sent into three , three-part message header , data, and information body tail .
header comprising: a synchronization header ( 2 bytes ) , the function code ( 1 byte ) , feature data ( 1 ) and the data length (n), a total of eight bytes.
data volume include : the actual data length is determined by the length of the header information items.
information Tail include : checksum ( 2 ) , the end of the code ( 2 ) , a total of 4 bytes.
tail and message header information is a fixed length , the body is variable-length data can be determined according to the length of the header information items.

received first receive a fixed-length header , and then based on the received data length information body , and finally receiving information tail. Note To receive respectively receive .  
2001-09-16 03:45:47
sending / receiving ends :
send / receive data module ( transport stream to fetch effective package , the key to how you send , N , or a combination of portfolio )
packet generation / parsing module ( by function code sent to different execution module characterization data processing , data fields ) generated
data field / implementation modules
2001-09-16 04:10:42
code structure how reasonable is what does this mean ?
2001-09-16 04:36:57
" code structure " What does it mean ? The above description seems no connection with the structure of the code , if the method of sending and receiving data , as long as the client receives the first header , then according to the header length can receive data back .
2001-09-16 05:13:56
code structure how reasonable is what does this mean ?
2001-09-16 05:50:43
Currently I am also considering server functions. Talk about my own personal thoughts . I think imitation ascii table , the better .
server will be a good one structure ( perhaps the n-th ) .
when customers

structure when the connection request then . . . .
initial ideas . . .
no experience .
2001-09-16 06:22:46
Maybe there are a lot of servers n constant metamorphosis . Ministry to test the gang idiot wrote it. -!
2001-09-16 06:58:36
how are OK , look at their own convenience on the line, there is no fixed pattern
2001-09-16 07:34:26
unpacking the client to consider the issue . TCP this point of sorts.
2001-09-16 07:55:29
is this code structure ah
such is
switch ( function code )
case & nbsp after receiving a packet ; Function Code 1:
      ...... // achieve functional code function 1
case   function Code 2:
      ...... // function code function to achieve such a large
2 structure it? I feel such a structure is not very good , after the package is not it will not convenient ?
If not, then what good structure it?
2001-09-16 08:18:51

Why are receiving the   once been sent is not very good . If the points repeatedly made ​​the case to use multithreading synchronization with knowledge of it ? According to the data to determine return after
many functions are sending data to perform a program of
2001-09-16 08:22:54
Now the question is : To execute a command would write two functions, one function to send data to the server , the server returns the data received after the SELECT   then jump to the first two functions to determine the results according to the function code
. Inside there is a way to write it in a function ? Such a program will need to write something thread it? Thank you . . Features are not much difference
  communication protocol between modules now do not understand , so I wrote the structure is not too messy   but after a bad package DLL. There on how to use the SELECT
DLL inside the window handle and message parameters , does not support the message map , right?