sendto Function
The sendto function sends data to a specific destination.
int sendto( __in SOCKET s, __in const char* buf, __in int len, __in int flags, __in const struct sockaddr* to, __in int tolen );
Parameters
-
s
-
Descriptor identifying a (possibly connected) socket.
buf
-
Buffer containing the data to be transmitted.
len
-
Length of the data in buf, in bytes.
flags
-
Indicator specifying the way in which the call is made.
to
-
Optional pointer to a sockaddr structure that contains the address of the target socket.
tolen
-
Size of the address in to, in bytes.
Return Value
If no error occurs, sendto returns the total number of bytes sent, which can be less than the number indicated by len. Otherwise, a value of SOCKET_ERROR is returned, and a specific error code can be retrieved by calling WSAGetLastError.
ecvfrom函数(经socket接收数据):
参数:
The recvfrom function receives a datagram and stores the source address.
int recvfrom( __in SOCKET s, __out char* buf, __in int len, __in int flags, __out struct sockaddr* from, __in_out int* fromlen );
Parameters
-
s
-
Descriptor identifying a bound socket.
buf
-
Buffer for the incoming data.
len
-
Length of buf, in bytes.
flags
-
Indicator specifying the way in which the call is made.
from
-
Optional pointer to a buffer in a sockaddr structure that will hold the source address upon return.
fromlen
-
Optional pointer to the size, in bytes, of the from buffer.
Return Value
If no error occurs, recvfrom returns the number of bytes received. If the connection has been gracefully closed, the return value is zero. Otherwise, a value of SOCKET_ERROR is returned, and a specific error code can be retrieved by calling WSAGetLastError.