send function (Winsock)

The send function transmits ordered data sent over a connection.


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

Parameters

Parameter Description
s A descriptor identifying a connected socket.
buf A buffer containing the data to be transmitted.
len The number of bytes to send from the buffer pointed to by the buf parameter.
flags Flags that influence the transmission behavior. (See Remarks for details).

Return Value

Type Description
SOCKET_ERROR A socket error occurred, and a specific error code can be retrieved by calling WSAGetLastError.
The number of bytes sent. If the call is successful, this will be the total number of bytes sent.

Remarks

  • The send function is used with connection-oriented protocols, such as the User Datagram Protocol (UDP) or the Transmission Control Protocol (TCP).
  • If the underlying transport supports the message semantics, the send function will transmit the entire message as a single unit.
  • If the flags parameter is set to 0, the send function will attempt to send all of the data in the buffer.
  • If the data is larger than the buffer capacity, the send function will send as much data as possible and return the number of bytes sent. The remaining data must be sent in subsequent calls.
  • Common values for the flags parameter include:
    • MSG_PARTIAL: Transmit data in partial.

Requirements

Client: Requires Windows Vista, Windows XP Professional x64 Edition, Windows XP, or Windows 2000 Professional.

Server: Requires Windows Server 2008, Windows Server 2003, or Windows 2000 Server.

Header: Ws2tcpip.h

Library: Ws2_32.lib

DLLs: Ws2_32.dll