Socket programming: porting from Linux to Windows

Source: Internet
Author: User

From: http://www.cic.tsinghua.edu.cn/jdx/book1/CHAPTER3.htm

 

Add the # include <winsock. h> statement to the source file.

Call the WSAStartup () function to initialize Windows Sockets DLL, and call the WSACleanup () function at the end to notify Windows Sockets DLL to release resources.

Change the SOCKET type to int type to SOCKET.

Do not use the global variable errno to obtain and set error codes. Change the value to the WSAGetLastError () function and WSASetLastError () function recommended by Windows Sockets.

Use the closesocket () function instead of the close () function to close the socket. Use the ioctlsocket () function instead of the ioctl () function and the fcntl () function to control the socket mode.

The getsockopt () function and setsockopt () function provide different support in Berkeley Sockets and Windows Sockets. The source program may need to be modified. For details, see Chapter 6 function usage instructions.

Change the structure fd_set in the source program to be modified by using the FD_XXX macro.

Change the error code in the source program to the constant value defined by WSA header recommended by Windows Sockets.

Set the pointer of the Windows Sockets application to the FAR type.

It is best to change the blocking call in the source program to the message-based Asynchronous Operation recommended by Windows Sockets.

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.