Differences between socket in Windows and Linux

Source: Internet
Author: User

 

Socket Windows Linux
Header file Winsock. h/winsock2.h Sys/socket. h error handling: errno. h
Socket Type Socket Int
Initialization Wsastartup is required for Windows.
Wsadata; err = wsastartup (0x202, & wsadata); If (Err! = 0) {return 0;} else if (lobyte (wsadata. wversion )! = 2 | hibyte (wsadata. wversion)
! = 2) // check whether this version of socket {wsacleanup (); Return 0;} is supported ;}
No
Reverse Initialization Wsacleanup (); No
Open socket Socket (...) Socket (...)
Disable socket Closesocket (...) Close (...)
Retrieval error? Wsagetlasterror () Extern int errno;
Int geterror () {return errno ;}

 
Set non-blocking Ioctlsocket (server_socket, fionbio, & UL); int ul = 1 Fcntl (server_socket, f_setfl, o_nonblock); <fcntl. h>

 
The last parameter of the send function. In Windows, it is generally set to 0. It must be the socket used by the following parameters. The maximum value (integer) is 1 (or msg_nosignal)
Millisecond-level acquisition Gettickcount () Gettimeofday ()
Socket operation error Return Value Socket_error Socket_error
Exception Handling No exception handling for send (). The last parameter is invalid. Write 0. 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 exits. 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.
Compile the connection Ws2_32.lib -Lstdc
Libstdc ++. so.5 is required during runtime. You can create a link in the/usr/lib directory.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.