1) header file WindowsWinsock. h/winsock2.h LinuxSys/Socket. H error handling: errno. h 2) initialization WindowsWsastartup Wsadata; Err = wsastartup (0x202, & wsadata); If (Err! = 0) { Return 0; } Else if (lobyte (wsadata. wversion )! = 2 | hibyte (wsadata. wversion )! = 2) // check whether this version is supportedSocket { Wsacleanup (); Return 0; } Wsacleanup () is used for exit cleaning (); LinuxNot Required 3) DisableSocket WindowsClosesocket (...) LinuxClose (...) 4)SocketType WindowsLowerSocket LinuxLower int 5) Get the error code WindowsWsagetlasterror () LinuxVariable errno Extern int errno; Int geterror () {return errno ;} 6) set non-blocking WindowsLower ioctlsocket (server _Socket, Fionbio, & UL); int ul = 1 LinuxFcntl (server _Socket, F_setfl, o_nonblock); <fcntl. h> 7) The last parameter of the send Function WindowsGenerally, it is set to 0. LinuxThe following parameters must be usedSocketMedium, the maximum number of values (integer) plus 1 (set to msg_nosignal) 8) millisecond-level acquisition WindowsGettickcount () LinuxGettimeofday () 9) Compile the connection WindowsWs2_32.lib LinuxLower -Lstdc Libstdc ++. so.5 is required during runtime. You can create a link in the/usr/lib directory. 10)SocketOperation error Return Value AllSocket_ Error. His value is-1. 11) Exception Handling WindowsNo exception handling for send (). The last parameter is invalid. Write 0. LinuxLower When the connection is disconnected and data is sent, not only will the return value of send () be reflected, but it will also send an exception message like the system. If it is not processed, the system will output brokepipe, the program will return. For this reason, the last parameter of the send () function can be set to msg_nosignal to prohibit the send () function from sending exception messages to the system. 12) WSA macro WindowsWSA-related operations LinuxWSA-related operations areLinuxNo, just remove it. 13) Multithreading Multithreading: (WIN) process. h --> --〉(Linux) Pthread. h _ Beginthread --> pthread_create _ Endthread --> pthread_exit |