send

This function sends data on a connected socket.

At a Glance

Header file: Winsock.h
Windows CE versions: 1.0 and later

Syntax

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

Parameters

s

[in] Descriptor that identifies a connected socket.

buf

[in] Buffer containing the data to be transmitted.

len

[in] Length of the data in buf.

flags

[in] Specifies the way in which the call is made.

Return Values

The total number of bytes sent, which can be less than the number indicated by len for nonblocking sockets, indicates that no errors occurred. SOCKET_ERROR indicates failure. To get a specific error value, call WSAGetLastError.

Remarks

For Infrared Sockets (IrSock), the Af_irda.h file must be explicitly included.

The send function is used to write outgoing data on a connected socket. For message-oriented sockets, care must be taken not to exceed the maximum packet size of the underlying provider, which can be obtained by using getsockopt to retrieve the value of socket option SO_MAX_MSG_SIZE. If the data is too long to pass atomically through the underlying protocol, the error WSAEMSGSIZE is returned, and no data is transmitted.

The successful completion of a send does not indicate that the data was successfully delivered.

If no buffer space is available within the transport system to hold the data to be transmitted, send will block unless the socket has been placed in a nonblocking mode. On nonblocking stream oriented sockets, the number of bytes written can be between 1 and the requested length, depending on buffer availability on both client and server machines. The select function can be used to determine when it is possible to send more data.

Calling send with a zero len parameter is permissible and will be treated by implementations as successful. In such cases, send will return zero as a valid value. For message-oriented sockets, a zero-length transport datagram is sent.

The flags parameter can be used to influence the behavior of the function beyond the options specified for the associated socket. The semantics of this function are determined by the socket options and the flags parameter. Windows CE supports the following flags parameter:

MSG_DONTROUTE

Specifies that the data should not be subject to routing. A Windows Sockets service provider can choose to ignore this flag.

See Also

bind, recv, recvfrom, socket, select, sendto, shutdown, WSAStartup