The difference between sockets in Windows and Linux

Updated on technology 2024-03-27
3 answers
  1. Anonymous users2024-02-07

    1.Header file.

    Windows or.

    Most of the netinet under Linux is here), the function is here), sys is already included in it, you can save it)

    2.Initialize.

    Under Windows, you need to start WS2 with wsastartupup, and you need to use pragma comment(lib,"ws2_32") to tell the compiler to link the lib.

    Not required under Linux.

    3.Turn off the socket

    closesocket (..) in Windows

    Linux: close(..

    4.Type.

    Windows socket

    linux int

    5.Obtain the error code.

    GetLastError() wsAgetLastError() under Windows

    Under Linux, socket operations that fail to be executed successfully will return -1; If it does, the errno variable is set.

    6.Set up non-blocking.

    IOCTLsocket() in Windows

    In Linux, fcntl() requires a header file.

    7.The last parameter of the send function.

    In Windows, this parameter is usually set to 0

    In Linux, it is best to set it to msg nosignal, if not, it may cause the program to quit after sending errors.

    8.Millisecond-level time acquisition.

    getTickCount() on Windows

    gettimeofday() in linux

  2. Anonymous users2024-02-06

    The socket should be the same in principle, but the operating mechanism of different systems is a little different.

    Socket programming problems encountered with Windows to Linux** porting.

    1. Porting of some commonly used functions.

    2. Network. Note that socket-related programs are ported from Windows to Linux.

    1) Header file.

    Windows.

    SYS under Linux

    Error handling: The header files of other common functions can be queried on the command line with the man command.

    2) Initialization.

    You need to use wsastartuplinux under windows (very convenient), you can use it directly.

    3) Close the socket

    closesocket (..) in Windows

    Linux: close(..

    4) Type. Windows socket

    In Linux, it is of the int type.

    5) The structure of the binding address.

    The names are the same, both are struct sockaddr, struct sockaddr in, these two are usually used conversionally;

  3. Anonymous users2024-02-05

    1) Header text search bibi, windows under sys error Script: The header file of other commonly used functions can be queried under the command line with man finger wheel leakage filial piety. 2) You need to use wsastartuplinux to initialize windows (very convenient), you can use it directly, 3) close socket under windows

Related questions
5 answers2024-03-27

Lots of differences....I don't know what the landlord is asking? >>>More

27 answers2024-03-27

Unless you redo your Vista system ...

I used to be also an XP plus a linux... It's only after the rework! >>>More

9 answers2024-03-27

Detect the Linux system.

The following describes whether to enable the FTP server >>>More

10 answers2024-03-27

sudo is a Linux system administration directive, which is a tool that allows system administrators to let ordinary users execute some or all of the root commands. >>>More

2 answers2024-03-27

1. Basic usage.

The basic usage of the grep command is to find a line in a file that contains a specified pattern. For example, to find a line in a file that contains example, you can run the following command: >>>More