There are many socket functions in windows. I have not introduced them in detail. The functions here are a brief description of their usage. For detailed usage, refer to msdn.
The main purpose here is to serve the following three application services.
Function Description:
---------
Wsastartup Function
Initialize Winsock
[Statement]
Int wsastarup (word wversionrequested, lpwsadata lpwsa
Data );
[Parameters]
Wversionrequested-the minimum version number of Winsock is required.
Lpwsadata-Winsock details
[Return value]
0 is returned when the function is successfully called.
A non-0 value is returned when the failure fails.
---
Socket Functions
Used to generate socket (soket descriptor)
[Statement]
Socket socket (int af, int type, int Protocol );
[Parameters]
Af-address family (usually used: af_inet)
Type-socket type
Sock_stream: used for TCP protocol
Sock_dgram: used for UDP protocol
Protocol-used protocol
[Return value]
When the function is successfully called, a new socket (socket descriptor) is returned)
Invalid_socket.
---
Inet_addr Function
Converts an IP address of "a. B .c.d" to a 32-bit long integer.
[Statement]
Unsigned long inet_addr (const char far * CP );
[Parameters]
CP-pointer to the IP address string
[Return value]
When the function is successfully called, the IP address represented by a 32-bit integer is returned.
Inaddr_none.
---
Gethostbyname Function
Obtain host information from the host name.
[Statement]
Struct hostent far * gethostbyname (const char far * Name );
[Parameters]
Name-pointer to the host name string
[Return value]
The host information is returned when the function is successfully called.
NULL (null) is returned when a failure occurs)
---
Recv Function
Use SOCKET to accept data.
[Statement]
Int Recv (socket S, char far * Buf, int Len, int flags );
[Parameters]
S-point to the socket descriptor generated by the socket function
Buf-pointer to the buffer (array) for receiving data
Len-buffer size
Flag-call method (msg_peek or MSG_OOB)
[Return value]
The number of bytes received when the request is successful.
If the connection is interrupted, 0 is returned.
Socket_error is returned when a failure occurs.
---
Sendto Function
Send data.
[Statement]
Int sendto (socket S, const char far * Buf, int Len, int flags, const struct sockaddr far * To, int token );
[Parameters]
S-point to the socket descriptor generated by the socket function
Buf-pointer to the buffer (array) for receiving data
Len-buffer size
Flag-call method (msg_dontroute, MSG_OOB)
To-pointer to the sender's socket address
Token-size of the sender's socket address
[Return value]
Returns the number of bytes that have been sent when the request is successful.
Socket_error is returned when a failure occurs.