Jump to main content

##

# 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

Parameters | Description
--- | ---
s | Socket descriptor returned from previous call to socket().
buf | Application data buffer containing data to transmit.
len | Length of data in bytes.
flags | Message 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.