send Function

C

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

Description

The send() function is used to send outgoing data on an already connected socket. This function is used to send a reliable, ordered stream of data bytes on a socket of type SOCK_STREAM but cal also be used to send datagrams on a socket of type SOCK_DGRAM.

Preconditions

The connect() function should be called for TCP and UDP sockets. Server side, accept() function should be called.

Parameters

ParametersDescription
sSocket descriptor returned from previous call to socket().
bufApplication data buffer containing data to transmit.
lenLength of data in bytes.
flagsMessage flags (currently this is not supported).

Returns

  • If the function is successful, the number of bytes sent is returned.

  • A return value of SOCKET_ERROR (-1) indicates an error and errno is set accordingly.

  • A value of zero indicates no data sent.

Remarks

None.