This function translate an UDP service, which is given as a string into a port
identifier, which is a 2-bytes integer.
The function returns the port identifier in the processor order or 0 if the
service has not been found into the file services.
Syntax: UdpServiceToPort (LPCSTR szService)
Arguments:
szService
|
The
service to be translated.
|
Returns:
unsigned
short
|
The
port identifier or 0 if error
|
Example : printf ("echo service is port %u\n", Udp4uServiceToPort ("echo"));
This function binds the Udp dialog to a given host. After this call, all
datagrams sent from another host are rejected by the library. Only those which
are sent by the given host are seen by the application. Moreover, all datagrams
sent by the application will be addressed to this host.
This association can be reset (default) by setting the bFilter parameter to
FALSE;
The remote host is either the host given in the UdpInit function (client mode)
or the host which has sent the last received datagram (server mode). This
behavior is specified by the nMode argument.
Syntax: UdpBind (LPUDPSOCK Udp, BOOL bFilter, int nMode)
Arguments:
Udp
|
The
descriptor returned by UdpInit.
|
BFilter
|
TRUE
in order to set an association, FALSE in order to remove the current association |
nMode
|
UDP4U_CLIENT
to receive datagrams only from the host given to UdpInit, UDP4U_SERVER to receive datagrams only from the host which has sent the previous datagram |
Returns:
TCP4U_SUCCESS
|
function
has succedeed
|
Example : LPUDPSOCK Udp; /* Udp4u descriptor */ UdpInit (& Udp, "www.myhost.fr", 7, 0); UdbBind (Udp, TRUE, UDP4U_CLIENT); /* Udp4u will ignore any datagram not sent by www.myhost.fr */ UdpRecv (Udp, sBuf, sizeof sBuf, 100, HFILE_ERROR); printf ("www.myhost.fr said <%s>\n", sBuf);
This function frees local resource. The application should call Tcp4uCleanup
before quitting.
Syntax: UdpCleanup (LPUDPSOCK Udp);
Arguments:
Udp
|
The
descriptor returned by UdpInit.
|
Returns:
TCP4U_ERROR
|
The
socket can not be closed. A blocking call is still in progress
|
TCP4U_SUCCESS
|
Successful
call
|
This function prepares an Udp dialog. It should be called before any other
Udp4u call, but after a successful Tcp4uInit.
If a local port is specified, the library will accept data only from this
port.
If no host is specified, the library is unable to sent data until a successful
UdpBind call.
Note: the port are given into the processor (natural) order.
Syntax: UdpInit (LPUDPSOCK *pUdp, LPCSTR szHost, unsigned short uRemotePort, unsigned short uLocalPort);
Arguments:
pUdp
|
A
pointer on a descriptor which will be returned by the Tcp4u library if the
function succeeds. This handle should be passed by the application to any Udp4u
call.
|
SzHost
|
The
host to be reached, or NULL
|
uRemotePort
|
The
remote service to be used or 0
|
uLocalPort
|
The
local service to be used or 0
|
Returns:
TCP4U_BINDERROR
|
Tcp4u
can not bind the socket to the specified local port
|
TCP4U_HOSTUNKNOWN
|
Tcp4u
can not resolve the address of the given host
|
TCP4U_NOMORESOCKET
|
Tcp4u
was unable to create a socket
|
TCP4U_INSMEMORY
|
Not
enough memory to create the UDPSOCK structure.
|
TCP4U_SUCCESS
|
The
socket has been created
|
Example : LPUDPSOCK Udp; /* Udp4u descriptor */ UdpInit (& Udp, "www.myhost.fr", 7, NULL);
This function receive a datagram. If the function UdpBind has been called, the
library will accepts only the datagrams sent by the current host.
Syntax: UdpRecv (LPUDPSOCK Udp, LPSTR sData, int nDataSize unsigned uTimeout, HFILE hf);
Arguments:
Udp
|
The
descriptor returned by UdpInit
|
sData
|
A
buffer which will be filled by the datagram
|
nDataSize
|
The
size of the user's buffer
|
uTimeout
|
The
timeout in second
|
hf
|
A
file handler into which the data will be written
|
Returns:
TCP4U_ERROR
|
An
error has occurred
|
TCP4U_CANCELLED
|
The
called was canceled by a signal or TcpAbort
|
TCP4U_TIMEOUT
|
Timeout
has occurred
|
TCP4U_SUCCESS
|
The
buffer has been sent
|
This function sends a datagram to the current host. The addressee is the host
given to the UdpInit function or the client host if a UdpBind has been called
in server mode.
Syntax: UdpSend (LPUDPSOCK Udp, LPCSTR szData, int nDataSize BOOL bHighPriority, HFILE hf);
Arguments:
Udp
|
The
descriptor returned by UdpInit
|
szData
|
The
data to be sent
|
nDataSize
|
The
number of bytes to be sent
|
bHighPriority
|
TRUE
if the string must be sent in Out Of Band mode
|
hf
|
A
file handler into which the data will be written
|
Returns:
TCP4U_ERROR
|
An
error has occurred
|
TCP4U_OVERFLOW
|
The
buffer to be sent exceeds the datagram size
|
TCP4U_SUCCESS
|
The
buffer has been sent
|