hb_inetDGramSend()

HB_INETDGRAMSEND()

Send data to a datagram socket

Syntax

      HB_INETDGRAMSEND( <socket>, <cAddress>, <nPort>, <cBuffer>;
                         [, <nSize> ] ) -> nBytesSent

Arguments

<socket> a socket previously created / opened

<cAddress>

<nPort>

<cBuffer>

<nSize>

Returns

Returns number of bytes sent, or -1 on error

Description

Sends a datagram (a fixed length data) to a determined ip address (cAddress, to be specified in quad-dot notation) and port.

If nSize is not specified, all the data in cBuffer will be sent; if nSize is specified, only the first nSize bytes of cBuffer will be sent.

There isn’t any guarantee that all the data required to be written is really sent to the socket: the calling program should check for the numeric return and send iteratively the unsent data to complete the message.

Anyway, the raw datagram is sent and received as once, and any data less than the system datagram size will be sent and received as a single item.

If the socket is created in broadcast mode, the cAddress element can be a broadcast address.

Returns -1 on error, or the number of bytes actually sent on success.

Compliance

Harbour

hb_inetDGramRecv()

HB_INETDGRAMRECV()

Get data from a datagram socket

Syntax

      HB_INETDGRAMRECV( <socket>, @<cBuffer> [, <nSize> ] ) ;
                         -> nBytesRead

Arguments

<socket> a socket previously created / opened

<cBuffer> is the target buffer and must be passed by reference

<nSize>

Returns

Returns number of bytes read, or -1 on error

Description

Reads at maximum nSize bytes incoming from a UDP socket, if nSize is given, or reads at maximum cBuffer length if nSize is not given.

There isn’t any guarantee that all the data required to be read is really sent from the kernel to the application: the kernel should just return the last complete datagram that has been received, up to nSize bytes.

Compliance

Harbour

hb_inetDGramBind()

HB_INETDGRAMBIND()

Create a bound datagram socket

Syntax

      HB_INETDGRAMBIND( <nPort>, [<cAddress> [, <lBroadcast>] ] ) ;
                        -> SOCKET

Arguments

<nPort>

<cAddress>

<bBroadcast>

Returns

An INET socket

Description

Creates a datagram-oriented socket and binds it to a particular port, and eventually to a certain interface if cAddress is given and not NIL.

If lBroadcast is set to .T., the routine creates a broadcast capable socket: it will be able to receive and send broadcast messages. On most systems this requires special user privileges.

Returns the socket

If an error occurs, the socket error message and code are set.

Compliance

Harbour

hb_inetDGram()

HB_INETDGRAM()

Create a datagram socket

Syntax

      HB_INETDGRAM( [<lBroadcast>] ) -> SOCKET

Arguments

lBroadcast

Returns

An INET socket

Description

Creates a datagram-oriented socket that will be able to send data and eventually receive data. Since the socket is not bound, the program can’t retrieve the address at which this socket appaers to be, but a second socket receiving a message sent from this one would be able to reply correctly with a datagram that can be read from a non-bound socket.

If lBroadcast is set to .T., the routine creates a broadcast capable socket: it will be able to receive and send broadcast messages. On most systems this requires special user privileges.

Returns the socket, and if an error occurs, the socket error message and code are set.

Compliance

Harbour