Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members | Related Pages

wvudp.h

Go to the documentation of this file.
00001 /* -*- Mode: C++ -*-
00002  * Worldvisions Weaver Software:
00003  *   Copyright (C) 1997-2002 Net Integration Technologies, Inc.
00004  *
00005  */
00006 #ifndef __WVUDP_H
00007 #define __WVUDP_H
00008 
00009 #include "wvfdstream.h"
00010 #include "wvaddr.h"
00011 
00012 /**
00013  * WvUDPStream can send and receive packets on a connectionless UDP socket.
00014  * 
00015  * In the constructor, the socket is attached using bind() to the given
00016  * _local address.  If the address is 0.0.0.0, all addresses on the local
00017  * host are used; if the port is 0, an available port number is chosen
00018  * automatically.
00019  * 
00020  * If the _rem address is 0.0.0.0, the port is not connect()ed.  That means
00021  * it can receive packets from anywhere and send them to anywhere.  The
00022  * src() and setdest() functions are useful for this.  If _rem is not 0.0.0.0,
00023  * connect() is called and the socket will only accept data to/from the
00024  * specified remote UDP address.
00025  * 
00026  * Buffering: all the usual WvStream-style input buffering is available,
00027  * including getline(), but because input packets may get lost it is of
00028  * limited usefulness.  Buffering will cause particular confusion if the
00029  * socket is not connect()ed.
00030  */
00031 class WvUDPStream : public WvFDStream
00032 {
00033 public:
00034     /** connect a new socket */
00035     WvUDPStream(const WvIPPortAddr &_local, const WvIPPortAddr &_rem);
00036     virtual ~WvUDPStream();
00037     
00038     const WvAddr *local() const;
00039     
00040     /**
00041      * return the remote address (source of incoming packets, target of
00042      * outgoing packets).  This is the last host sent to or received from,
00043      * whichever was more recent.
00044      */
00045     virtual const WvAddr *src() const;
00046     void setdest(const WvIPPortAddr &_remaddr)
00047         { remaddr = _remaddr; }
00048     
00049     void enable_broadcasts();
00050 
00051 protected:
00052     WvIPPortAddr localaddr, remaddr;
00053     
00054     virtual size_t uread(void *buf, size_t count);
00055     virtual size_t uwrite(const void *buf, size_t count);
00056 };
00057 
00058 
00059 #endif // __WVUDP_H

Generated on Sat Mar 13 14:56:00 2004 for WvStreams by doxygen 1.3.6-20040222