udpRead()

Reads the data from a UDP socket.

Synopsis

int udpRead( int socket, string/blob &data, string &host, unsigned &port, time maxTimeout);

Parameters

Parameter Description
socket Number of the socket (to which the function udpOpen() established a connection).
data Data to be read. If you use a string and the data contains 0 bytes, the function replaces each of the 0 bytes by "." and the log viewer shows a message.
host Return parameter. Host from which the data was sent.
port Return parameter. Port over which the data was sent.
maxTimeout Time range the function waits for the data.

Return value

0 if the function starts correctly (the timeout starts), in case of parameter errors -1. You can retrieve errors by using getLastError().

Error

Missing or wrong arguments.

Description

Reads the data from a UDP socket. In the return parameters host and port the sender of the data and sending port are returned. The host is always returned in numerical form to avoid delays due to host name lookup. To determine the host name, the function getHostByAddr() has to be called afterwards.

Example

Opens the connection to a UDP socket via udpOpen() and reads the data of the opened socket via udpRead().

main()
{
  int read, open;
  time maxTime;
  string data;
  time maxTime = 100;
  unsigned openPort, writePort;
  string writeHost;
  openPort = 120;
  open = udpOpen("eiwnt094", openPort);
  DebugN(open);
  read = udpRead(open, data, writeHost, writePort, maxTime);
  DebugN(data, writeHost, writePort); 
}

Assignment

Communication functions

Availability

CTRL