class CAVERNplus_udp_c : public CAVERNplus_socketbase_c

UDP Class

Inheritance:


Public Methods

CAVERNplus_udp_c* clone ()
Make a clone of the current udp object
void close ()
Close the udp handle
void copyReceiveAddressToSendAddress ()
Copy the receive address to send address
int init (unsigned short port = 0)
Open a socket
void makeNonBlocking ()
Make a connection non blocking.
int peek (char *message, int length)
Peek at incoming packet. - without extracting it from the queue.
void printInfo ()
Print information on the connection (IP address, port number etc).
int receive (char *message, int length)
Receive data
int send (char *message, int length)
Send data.
int setSendAddress (char *host, unsigned short port)
Set address to send to

Public


Accessor Functions
unsigned long getReceiveIP ()
Get an incoming packet's originating address.
void getReceiveIP (char *ip)
Get an incoming packet's originating address.
unsigned short getReceivePort ()
Get an incoming packet's originating port.
unsigned long getSendIP ()
Get outgoing packet's destination address.
void getSendIP (char *ip)
Get outgoing packet's destination address.
unsigned short getSendPort ()
Get outgoing packet's destination port.
unsigned long getSelfIP ()
Get your own IP.
void getSelfIP (char *ip)
Get your own IP.
unsigned short getSelfPort ()
Get your own port.

Private Fields

struct sockaddr_in selfAddress sendAddressreceiveAddress
Socket structures.
int sockfd
Socket file descriptor.

Inherited from CAVERNplus_socketbase_c:

Public Methods

void expandHostName(char *src, char *newname, int len)
double getAverageReceiveBandwidth()
double getAverageSendBandwidth()
void getHostName(char *name, int len)
double getInstantReceiveBandwidth()
double getInstantSendBandwidth()
double getTimeInSecs()
unsigned long getTotalDataReceived()
unsigned long getTotalDataSent()
int hostnameToIP(char *hostname, char* hostIP)
void ipNumToString(unsigned int ip, char *ipstring)
void showStats()

Documentation

UDP Class. This class bypasses CAVERN's standard method for establishing connections and provides the user with direct control of UDP connections. The idea is that you first create a udp object and then call the init() method. (see init() method for more details).

Then you can either Send data to a destination or receive any incoming data.

To send data to a destination you need to set the destination with the SetSendAddress method and then call the Send method.

To receive data, simply call the Receive method.

By default the connections are BLOCKING, meaning, if you call Receive and there is no data available to read your program will block until something comes along. To make your receives non blocking, call the MakeNonBlocking method.

int init(unsigned short port = 0)
Open a socket
Parameters:
port - Specifies port number. With the port parameter omitted a dynamic port will be established. Dynamic ports are typically used if you intend to be a client program sending packets to a server. If you are a server then you need to specify some specific port number. Port numbers must be > 6000.

int setSendAddress(char *host, unsigned short port)
Set address to send to. After a socket is open, you can create a connection to some other listener if you know their address and port

void copyReceiveAddressToSendAddress()
Copy the receive address to send address. You can do this if you want to send a message back to the receiver.

CAVERNplus_udp_c* clone()
Make a clone of the current udp object. This is useful when you get multiple udp messages coming in from different sources and you want to save their return addresses so that you can reply to them. Typically you do a clone and then call CopyReceiveAddresToSendAddress.
See Also:
CopyReceiveAddresToSendAddress

int receive(char *message, int length)
Receive data
Returns:
The number of bytes found in the packet. If a -1 is found then there might be a read error. Check the global variable errno. If you are using NON blocking and errno is EWOULDBLOCK then that's ok, it simply means you attempted a read but no data was available. If its not EWOULDBLOCK then you have a real error. To find out what the error means call: perror() - this is a UNIX call.
Parameters:
length - If length is set to smaller than actual incoming packet size, then the remaining bytes of packet is discarded. If length is set to larger than actual packet size, then only the number of bytes available in the packet is retrieved.

void close()
Close the udp handle. Must not do this as a destructor or you will disconnect a connection that might be still held by another client object. Only do this explicitly when you want to close a connection.


This class has no child classes.
Author:
(C) 1996 Jason Leigh
Version:
Version 5/26/97

alphabetic index hierarchy of classes


this page has been generated automatically by doc++

(c)opyright by Malte Zöckler, Roland Wunderling
contact: doc++@zib.de