The socket call sends data on a connected socket.
Syntax
#include <types.h> #include <sys\socket.h> int send(s, msg, len, flags) int s; char *msg; int len; int flags;
Parameters
s
MSG_DONTROUTE
Description
This call sends data on the socket with descriptor s. The send() call applies to connected sockets. For information on how to use send() with datagram and raw sockets, see Datagram or Raw Sockets. The sendto() and sendmsg() calls can be used with unconnected or connected sockets.
To broadcast on a socket, first issue a setsockopt() call using the SO_BROADCAST option to gain broadcast permission.
Specify the length of the message with the len parameter. If the message is too long to pass through the underlying protocol, the system returns an error and does not transmit the message.
No indication of failure to deliver is implied in a send() call. A return value of -1 indicates some locally detected errors.
If buffer space is not available at the socket to hold the message to be sent, the send() call normally blocks, unless the socket is placed in nonblocking mode. See ioctl() for a description of how to set nonblocking mode. Use the select() call to determine when it is possible to send more data.
Return Values
When successful, the number of bytes of the socket with descriptor s that is added to the send buffer is returned. This may be less than the number of bytes specified in the length parameter. Successful completion does not imply that the data has already been delivered to the receiver. The return value -1 indicates an error was detected on the sending side of the connection. You can get the specific error code by calling sock_errno() or psock_errno().
Error Code
Related Calls
send_file() connect()
getsockopt()
ioctl()
readv()
recv()
recvfrom()
recvmsg()
select()
sendmsg()
sendto()
setsockopt()
shutdown()
sock_errno()
socket()
writev()