The SockSentTo() call sends data to a connected or unconnected socket.
>>--SockSendTo(socket, data--+-----------+--, address)------------------->< +--, flags--+
is the socket descriptor.
is a string of data to be transmitted.
is a blank delimited list of options:
sends out-of-band data to sockets that support SOCK_STREAM communication.
turns on the SO_DONTROUTE option for the duration of the send operation. This option is usually only used by diagnostic or routing programs.
is a stem variable containing the destination address.
SockSendTo() sends data to a connected or unconnected socket with descriptor socket. For unconnected datagram and raw sockets, it sends data to the specified destination address. For stream sockets, the destination address is ignored.
Datagram sockets are connected by calling SockConnect(). This call identifies the peer to send or receive the datagram. After a datagram socket is connected to a peer, you can still use the SockSendTo() call but you cannot include a destination address.
To change the peer address when using connected datagram sockets, issue SockConnect() with a null address. Specifying a null address removes the peer address specification. You can then issue either a SockSendTo() call and specify a different destination address or a SockConnect() call to connect to a different peer. For more information on connecting datagram sockets and specifying null addresses, see Datagram or raw sockets.
If successful, the number of bytes sent is returned. Successful completion does not guarantee that the data is delivered to the receiver. The return value -1 indicates that an error was detected on the sending side. You can get the specific error code SockSock_Errno() or SockPSock_Errno(). Possible values are:
socket is not a valid socket descriptor.
The message data was too big to be sent as a single datagram.
There is no buffer space available to send the message.
socket is in nonblocking mode, the data cannot be sent without blocking, or the SO_SNDTIMEO option has been set for socket and the timeout expired before any data was sent.
The socket is not connected.
Destination address required.
Note: SockSendTo() interfaces with the C function sendto().