Difference between revisions of "Net protocol"
From X-Moto
(→Sub packets) |
(→Scenario) |
||
Line 40: | Line 40: | ||
* the server know which tcp connection is bind to which udp connection (several clients could have the same ip) and can send packets via the udp way. | * the server know which tcp connection is bind to which udp connection (several clients could have the same ip) and can send packets via the udp way. | ||
* the server sends the connected client list with a NA_changeClients netAction | * the server sends the connected client list with a NA_changeClients netAction | ||
+ | |||
+ | == Examples == |
Revision as of 13:46, 14 October 2008
Contents
Architecture
Server side
- 2 ports : port 4130 TCP, and port 4130 UDP
Client side
- 1 or 2 ports if possible : random ports
Main packet
Format:
[size of the subheader+subpacket written in ascii]\n ===> beginning of the subheader [source written in ascii]\n [subsource written in ascii]\n [actionType]\n ===> beginning of the subpacket [subpacket]\n
- source : -1 for the server, or the uniq number associated to the client
- subsource : the client subsource (0, 1, 2 or 3), for the player on the client machine
- action type : name of the netAction
- subpacket : specific to the netAction. \n is added at each subpacket so that it's more readable on a network sniffer, moreover, it can be used to be replaced by \0 to get the char.
For each NetAction, you have these two functions: send and NetAction(void* data, int len). When you send, you don't have to add the \n while it's added after. When you received, the len value includes the \n which is in data so that you can use it to retrieve the data easily (by replacing it by \0)
Sub packets
NA_clientInfos
NA_udpBind
NA_udpBindQuery
NA_chatMessage
NA_serverError
NA_frame
NA_changeName
NA_playingLevel
NA_changeClients
Scenario
- the client connects via TCP
- the client sends a NA_clientInfos netAction via TCP
- the server sends a NA_udpBindQuery netAction to the client via TCP
- the client sends 3 TNA_udpBind netActions via UDP to the server
- the server know which tcp connection is bind to which udp connection (several clients could have the same ip) and can send packets via the udp way.
- the server sends the connected client list with a NA_changeClients netAction