1, WSAStartup function is used to initialize Winsock [declaration] int WSASTARUP (Word WversionRequested, LPWSADATA LPWSADATA); [Parameter] WVersionRequested - Requires Details of the Minimum of Winsock LPWSADATA - WINSOCK [Return Value] When the function is successfully called, return 0 Returns non-0 value when failing
2, the Socket function is used to generate socket (SOKET Descriptor) [declaration] Socket Socket (int AF, int type, int protocol); [parameter] AF - address family (usually: af_inet) Type - SOCKET Type SOCK_STREAM: Used for TCP protocol SOCK_DGRAM: Used for UDP Protocol Protocol - The protocol used [Return Value] Returns an Invalid_Socket when the function is successfully called.
3, the inet_addr function converts the 10-based IP address "XXX.XXX.XXX.XXX" to 32-bit integer representation method [declaration] unsigned long inet_addr (const char far * cp); [parameter] cp - pointing The pointer of the IP address string representing the IP address string with "xxx.xxx.xxx.xxx" 10, return to the IP address represented by the 32-bit integer when the function is successfully called (order sequence according to the network byte) Returns INADDR_NONE.
4, the gethostbyname function can get host information from the hostname. [Declaration] Struct Hostent Far * gethostByName (const char far * name); [Parameter] Name - Pointer to the host name string [Return value] When the function is successfully called, return Returns null (null value) when the host information fails
5. Bind function Specifies the port number used by the local IP address to use [Declaration] Int Bind (Socket S, Const Struct Sockaddr Far * Addr, Int Namelen); [Parameters] S - point to Socket DescriptOrAddr generated with a socket function - pointing Socket address pointer Namelen - the length of the address. [Return value] Returns Socket_ERROR when the function is called when the function is successfully invoked
6, the Connect function is used to establish a connection with the server, send a connection request, must specify the IP address and port number of the server in the parameter [Declaration] INT Connect (Socket S, Const Struct Sockaddr Far * Name, Int Namelen); [Parameter] s - Pointer Socket DescriptorName Generated with Socket Functions Namelen - The length of the server address. [Return Value] Return to 0 When the function is successfully invoked, return to Socket_ERROR
7, the SELECT function can be used to investigate the status of one or more sockets. [Declaration] INT SELECT (INT NFDS, FD_SET FAR * READFDS, FD_SET FAR * WRITEFDS, FD_SET FAR * EXCEPTFDS, Const Struct Timeval Far * Timeout); [Parameter ] NFDS - This parameter can be ignored in the Windows Socket API, typically assigning NILL values readfds - due to the pointer of the accepted Socket device WRITEFDS - a pointer to the Socket device for transmitting data - Check the wrong status Timeout - timeout setting [Back Value] When returning to a value greater than 0, it means that the number of Socket complusses is returned to 0 indicates that the timeout failure returns Socket_ERROR
8. The RECV function is used to accept data using Socket. [Declaration] INT Recv (Socket S, Char Far * BUF, INT LEN, INT LEN, INT FLAGS); [Parameters] S - point to Socket DescriptorBuf-Accept Data Buffer with Socket Function (Array) The size of the pointer of the LEN - Buffer FLAG - Call mode (MSG_PEEK or MSG_OOB) [Return Value] Return to the number of bytes when successfully. If the connection is interrupted, return 0 failure Return Socket_ERROR9, Sendto functions utilize Socket Transfer data. [Declaration] INT Sendto (Socket S, Const Char Far * Buf, Int Len, Int Flags, Int token); [Parameters] S - point to Socket DescriptorBuf generated with socket functions - The size of the pointer of the buffer (array) of the data, the size of the size of the buffer (MSG_DONTROUTE, MSG_OOB) TO - Pointer to the sender Socket address token - Send a Socket address size [Return Value] When successfully returned The number of bytes sent. Return to Socket_ERROR when fails