SockSendTo

The SockSentTo() call sends data to a connected or unconnected socket.

Syntax:

>>--SockSendTo(socket, data--+-----------+--, address)-------------------><
                             +--, flags--+

where:

socket

is the socket descriptor.

data

is a string of data to be transmitted.

flags

is a blank delimited list of options:

MSG_OOB

sends out-of-band data to sockets that support SOCK_STREAM communication.

MSG_DONTROUTE

turns on the SO_DONTROUTE option for the duration of the send operation. This option is usually only used by diagnostic or routing programs.

address

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.

Return values:

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:

ENOTSOCK

socket is not a valid socket descriptor.

EMSGSIZE

The message data was too big to be sent as a single datagram.

ENOBUFS

There is no buffer space available to send the message.

EWOULDBLOCK

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.

ENOTCONN

The socket is not connected.

EDESTADDRREQ

Destination address required.

Note: SockSendTo() interfaces with the C function sendto().