1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225
|
.TH "UDPSocket" 3 "19 Jul 2003" "CommonC++" \" -*- nroff -*-
.ad l
.nh
.SH NAME
UDPSocket \- UDP sockets implement the TCP SOCK_DGRAM UDP protocol. Unreliable Datagram Protocol sockets.
.SH SYNOPSIS
.br
.PP
\fC#include <socket.h>\fP
.PP
Inherits \fBSocket\fP.
.PP
Inherited by \fBUDPBroadcast\fP, \fBUDPReceive\fP\fC [protected]\fP, and \fBUDPTransmit\fP\fC [protected]\fP.
.PP
.SS "Public Methods"
.in +1c
.ti -1c
.RI "\fBUDPSocket\fP (void)"
.br
.RI "\fICreate an unbound UDP socket, mostly for internal use.\fP"
.ti -1c
.RI "\fBUDPSocket\fP (const \fBInetAddress\fP &bind, \fBtpport_t\fP port)"
.br
.RI "\fICreate a UDP socket and bind it to a specific interface and port address so that other UDP sockets on remote machines (or the same host) may find and send UDP messages to it.\fP"
.ti -1c
.RI "virtual \fB~UDPSocket\fP ()"
.br
.RI "\fIDestroy a UDP socket as a socket.\fP"
.ti -1c
.RI "void \fBsetPeer\fP (const \fBInetHostAddress\fP &host, \fBtpport_t\fP port)"
.br
.RI "\fIset the peer address to send message packets to.\fP"
.ti -1c
.RI "\fBSocket::Error\fP \fBgetInterfaceIndex\fP (const char *ethX, int &InterfaceIndex)"
.br
.RI "\fIget the interface index for a named network device\fP"
.ti -1c
.RI "\fBSocket::Error\fP \fBjoin\fP (const \fBInetMcastAddress\fP &ia, int InterfaceIndex)"
.br
.RI "\fIjoin a multicast group on a particular interface\fP"
.ti -1c
.RI "int \fBsend\fP (const void *buf, size_t len)"
.br
.RI "\fISend a message packet to a peer host.\fP"
.ti -1c
.RI "int \fBreceive\fP (void *buf, size_t len)"
.br
.RI "\fIReceive a message from any host.\fP"
.ti -1c
.RI "\fBInetHostAddress\fP \fBgetPeer\fP (\fBtpport_t\fP *port=NULL) const"
.br
.RI "\fIExamine address of sender of next waiting packet.\fP"
.ti -1c
.RI "int \fBpeek\fP (void *buf, size_t len)"
.br
.RI "\fIExamine contents of next waiting packet.\fP"
.in -1c
.SS "Protected Attributes"
.in +1c
.ti -1c
.RI "sockaddr_in \fBpeer\fP"
.br
.in -1c
.SH "DETAILED DESCRIPTION"
.PP
UDP sockets implement the TCP SOCK_DGRAM UDP protocol. Unreliable Datagram Protocol sockets.
.PP
They can be used to pass unverified messages between hosts, or to broadcast a specific message to an entire subnet. Please note that Streaming of realtime data commonly use \fBUDPDuplex\fP related classes rather than UDPSocket.
.PP
In addition to connected TCP sessions, Common C++ supports UDP sockets and these also cover a range of functionality. Like a \fBTCPSocket\fP, A UDPSocket can be created bound to a specific network interface and/or port address, though this is not required. UDP sockets also are usually either connected or otherwise 'associated' with a specific 'peer' UDP socket. Since UDP sockets operate through discreet packets, there are no streaming operators used with UDP sockets.
.PP
In addition to the UDP 'socket' class, there is a '\fBUDPBroadcast\fP' class. The \fBUDPBroadcast\fP is a socket that is set to send messages to a subnet as a whole rather than to an individual peer socket that it may be associated with.
.PP
UDP sockets are often used for building 'realtime' media streaming protocols and full duplex messaging services. When used in this manner, typically a pair of UDP sockets are used together; one socket is used to send and the other to receive data with an associated pair of UDP sockets on a 'peer' host. This concept is represented through the Common C++ \fBUDPDuplex\fP object, which is a pair of sockets that communicate with another \fBUDPDuplex\fP pair.
.PP
\fBAuthor: \fP
.in +1c
David Sugar <dyfet@ostel.com>
.PP
.SH "CONSTRUCTOR & DESTRUCTOR DOCUMENTATION"
.PP
.SS "UDPSocket::UDPSocket (void)"
.PP
Create an unbound UDP socket, mostly for internal use.
.PP
.SS "UDPSocket::UDPSocket (const \fBInetAddress\fP & bind, \fBtpport_t\fP port)"
.PP
Create a UDP socket and bind it to a specific interface and port address so that other UDP sockets on remote machines (or the same host) may find and send UDP messages to it.
.PP
On failure to bind, an exception is thrown.
.PP
\fBParameters: \fP
.in +1c
.TP
\fB\fIbind\fP\fP
address to bind this socket to.
.TP
\fB\fIport\fP\fP
number to bind this socket to.
.SS "virtual UDPSocket::~UDPSocket ()\fC [virtual]\fP"
.PP
Destroy a UDP socket as a socket.
.PP
.SH "MEMBER FUNCTION DOCUMENTATION"
.PP
.SS "\fBSocket::Error\fP UDPSocket::getInterfaceIndex (const char * ethX, int & InterfaceIndex)"
.PP
get the interface index for a named network device
.PP
\fBParameters: \fP
.in +1c
.TP
\fB\fIethX\fP\fP
is device name, like 'eth0' or 'eth1'
.TP
\fB\fIInterfaceIndex\fP\fP
is the index value returned by os
.PP
\fBTodo: \fP
.in +1c
Win32 implementation.
.SS "\fBInetHostAddress\fP UDPSocket::getPeer (\fBtpport_t\fP * port = NULL) const"
.PP
Examine address of sender of next waiting packet.
.PP
This also sets 'peer' address to the sender so that the next 'send' message acts as a 'reply'. This additional behavior overides the standard socket getSender behavior.
.PP
\fBParameters: \fP
.in +1c
.TP
\fB\fIport\fP\fP
pointer to hold port number.
.PP
Reimplemented from \fBSocket\fP.
.SS "\fBSocket::Error\fP UDPSocket::join (const \fBInetMcastAddress\fP & ia, int InterfaceIndex)"
.PP
join a multicast group on a particular interface
.PP
\fBParameters: \fP
.in +1c
.TP
\fB\fIia\fP\fP
is the multicast address to use
.TP
\fB\fIInterfaceIndex\fP\fP
is the index value returned by getInterfaceIndex
.PP
\fBTodo: \fP
.in +1c
Win32 implementation.
.SS "int UDPSocket::peek (void * buf, size_t len)\fC [inline]\fP"
.PP
Examine contents of next waiting packet.
.PP
\fBParameters: \fP
.in +1c
.TP
\fB\fIbuf\fP\fP
pointer to packet buffer for contents.
.TP
\fB\fIlen\fP\fP
of packet buffer.
.PP
\fBReturns: \fP
.in +1c
number of bytes examined.
.SS "int UDPSocket::receive (void * buf, size_t len)\fC [inline]\fP"
.PP
Receive a message from any host.
.PP
\fBParameters: \fP
.in +1c
.TP
\fB\fIbuf\fP\fP
pointer to packet buffer to receive.
.TP
\fB\fIlen\fP\fP
of packet buffer to receive.
.PP
\fBReturns: \fP
.in +1c
number of bytes received.
.PP
Reimplemented in \fBUDPReceive\fP.
.SS "int UDPSocket::send (const void * buf, size_t len)\fC [inline]\fP"
.PP
Send a message packet to a peer host.
.PP
\fBParameters: \fP
.in +1c
.TP
\fB\fIbuf\fP\fP
pointer to packet buffer to send.
.TP
\fB\fIlen\fP\fP
of packet buffer to send.
.PP
\fBReturns: \fP
.in +1c
number of bytes sent.
.SS "void UDPSocket::setPeer (const \fBInetHostAddress\fP & host, \fBtpport_t\fP port)"
.PP
set the peer address to send message packets to.
.PP
This can be set before every \fBsend()\fP call if nessisary.
.PP
\fBParameters: \fP
.in +1c
.TP
\fB\fIhost\fP\fP
address to send packets to.
.TP
\fB\fIport\fP\fP
number to deliver packets to.
.SH "MEMBER DATA DOCUMENTATION"
.PP
.SS "struct sockaddr_in UDPSocket::peer\fC [protected]\fP"
.PP
.SH "AUTHOR"
.PP
Generated automatically by Doxygen for CommonC++ from the source code.
|