send Function (Winsock)

The send function sends data on a connected socket.

Syntax

int send(
  _In_  SOCKET s,
  _In_  const char *buf,
  _In_  int len,
  _In_  int flags
);

Parameters

Parameter Description
s A descriptor identifying a connected socket.
buf A pointer to a buffer containing the data to be sent.
len The number of bytes to send from the buffer pointed to by the buf parameter.
flags Flags that specify the way the call is processed.

Return Value

If no error occurs, send returns the number of bytes actually sent. Otherwise, a value ofSOCKET_ERROR is returned, and a specific error code can be retrieved by calling WSAGetLastError.

If s is a nonblocking socket, send can return WSAEWOULDBLOCK even if it has sent some data. In this case, the application must save the remaining data and attempt to send it later.

Remarks

The send function is used with connection-oriented protocols, such as the TCP protocol. For datagram sockets, use sendto.

If the connection has been broken, send will fail. If there is more data to be sent than the underlying transport provider can accept at once, send will send as much data as it can and return the number of bytes sent.

The flags parameter can be used to influence the behavior of the function call beyond the options specified by protocol. If you do not want to specify any flags, set this parameter to 0.

Flags

The following flags are supported:

  • MSG_PARTIAL: Indicates that the data is the beginning of a larger message. This flag is specific to certain protocols.
  • MSG_OOB: Sends data out-of-band.
Note: For TCP/IP sockets, the send function will send as much data as is available in the send buffer. It is possible that not all data specified by the len parameter is sent in a single call. The application must compare the return value with the original length of data to be sent and retransmit any remaining data if necessary.

See Also