Microsoft Windows CE 3.0  

sendto

Important:
This is retired content. This content is outdated and is no longer being maintained. It is provided as a courtesy for individuals who are still using these technologies. This content may contain URLs that were valid when originally published, but now link to sites or pages that no longer exist.

This function sends data to a specific destination.

int
sendto
(
SOCKET
s
,
const
char
*
buf
,
int
len
,
int
flags
,
const
struct
sockaddr
*
to
,
int
tolen
);

Parameters

s
[in] Descriptor that identifies a (possibly connected) socket.
buf
[in] Buffer that contains the data to be transmitted.
len
[in] Length of the data in buf.
flags
[in] Specifies the way in which the call is made.
to
[in] Optional pointer to the address of the target socket.
tolen
[in] Size of the address in to.

Return Values

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

Remarks

The sendtofunction is used to write outgoing data on a socket. For message-oriented sockets, care must be taken not to exceed the maximum packet size of the underlying subnets. If the data is too long to pass atomically through the underlying protocol, the error WSAEMSGSIZE is returned and no data is transmitted.

The toparameter can be any valid address in the socket's address family, including a broadcast or any multicast address. To send to a broadcast address, an application must have used setsockoptwith SO_BROADCAST enabled. Otherwise, sendtowill fail with the error value WSAEACCES. For TCP/IP, an application can send to any multicast address (without becoming a group member).

If the socket is unbound, unique values are assigned to the local association by the system, and the socket is then marked as bound. An application can use getsocknameto determine the local socket name in this case.

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

The sendtofunction is normally used on a connectionless socket to send a datagram to a specific peer socket identified by the toparameter. Even if the connectionless socket has been previously connected to a specific address, the toparameter overrides the destination address for that particular datagram only. On a connection-oriented socket, the toand tolenparameters are ignored, making sendtoequivalent to send.

For Sockets Using IP (Version 4)

To send a broadcast (on a SOCK_DGRAM only), the address in the toparameter should be constructed using the special IP address INADDR_BROADCAST (defined in Winsock.h), together with the intended port number. It is generally inadvisable for a broadcast datagram to exceed the size at which fragmentation can occur, which implies that the data portion of the datagram (excluding headers) should not exceed 512 bytes.

If no buffer space is available within the transport system to hold the data to be transmitted, sendtowill 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 the client and server systems. The selectfunction can be used to determine when it is possible to send more data.

Calling sendtowith a lenof zero is permissible and will return zero as a valid value. For message-oriented sockets, a zero-length transport datagram is sent.

The flagsparameter is used to influence the behavior of the function beyond the options specified for the associated socket. However, Windows CE silently ignores the MSG_DONTROUTE value and does not support MSG_OOB.

Requirements

Runs on Versions Defined in Include Link to
Windows CE OS 1.0 and later Winsock.h    
Note   This API is part of the complete Windows CE OS package as provided by Microsoft. The functionality of a particular platform is determined by the original equipment manufacturer (OEM) and some devices may not support this API.

See Also

recv, recvfrom, socket, select, send, shutdown, WSAStartup