|
Quake源代碼分析(草稿).5(1)
網絡部分補充說明: 負責傳送網間封包Sys_SendPacket()函數,調用了sendto這個Win socket API,它的作用是: The sendto function is normally used on a connectionless socket to send a datagram to a specific peer socket identified by the to parameter. Even if the connectionless socket has been previously connected to a specific address, the to parameter overrides the destination address for that particular datagram only. On a connection-oriented socket, the to and tolen parameters are ignored, making sendto equivalent to send. 所以很明顯,使用sendto並不需要建立可靠的連接,也就是不必先調用connect,直接能夠發送datagram.
客戶端連接服務器端的步驟: 1. 客戶端執行CL_Connect_f() 如果客戶端連接的服務器不是本地機器,需要多执行SVC_GetChallenge这一步 cls.state置為CA_CONNECTING. 判斷語句如下: cls.state=NET_IsLocalAddress(&clc.server_address)?CA_CHALLENGING: CA_CONNECTING; 2. 如果客戶端變量cls.state = CA_CONNECTING,那麼當系統執行到 CL_CheckForResend()時就會啟動 NET_OutOfBandPrint( NS_CLIENT, &clc.server_address, "getchallenge" ); 發送”getchallenge”消息給服務器端 3. 服務器端接收到”getchallenge”消息就會調用SVC_GetChallenge()à NET_OutOfBandPrint(NS_SERVER,address,"challengeResponse %i", challenge ); 發送”challengeResponse”消息給客戶端 4. 客戶端接受到”challengeResponse”消息: cls.state = CA_CHALLENGING; 5. 如果客戶端變量cls.state = CA_CHALLENGING,那麼當系統執行到 CL_CheckForResend()時就會啟動
|