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
|
<HTML><HEAD><TITLE>TCPSocket Class</TITLE></HEAD>
<BODY bgcolor="#ffffff">
<H1>TCPSocket Class Reference</H1>
<p>
[<A HREF="index.html">APE Index</A>] [<A HREF="hier.html">APE Hierarchy</A>]
[<A HREF="header-list.html">Headers</A>]
</p>
<HR>
<P>reliable connected TCP stream sockets. <a href="#short">More...</a></P>
<P>
<code>
#include <<a href="socket-h.html">socket.h</a>>
</code>
</P>
<P>
Inherits: <a href="Socket.html">Socket</a>
<P>
<H2>Public Members</H2>
<UL>
<LI> <b><a href="#ref0">TCPSocket</a></b> (InetAddress &bind, short port, int backlog)
</LI>
<LI> <b><a href="#ref1">TCPSocket</a></b> (InetHostAddress &host, short port)
</LI>
<LI> <b><a href="#ref2">TCPSocket</a></b> (TCPSocket &server)
</LI>
<LI> <b><a href="#ref3">TCPSocket</a></b> (TCPSocket *server)
</LI>
<LI> <b><a href="#ref4">TCPSocket</a></b> (void)
</LI>
<LI>virtual bool <b><a href="#ref5">OnAccept</a></b> (InetHostAddress ia, short port)
</LI>
<LI>int <b><a href="#ref6">Readline</a></b> (char *buf, size_t max)
</LI>
<LI>InetHostAddress <b><a href="#ref7">getHost</a></b> (short *port = NULL)
</LI>
<LI>InetHostAddress <b><a href="#ref8">getPeer</a></b> (short *port = NULL)
</LI>
<LI>friend inline int <b><a name="ref9">readline</a></b> (TCPSocket &s, char *buf, size_t max)
</LI>
</UL>
<HR>
<H2><a name="short">Detailed Description</a></H2>
<P>
TCP sockets are used for stream based connected sessions between two
sockets. Both error recovery and flow control operate transparently
for a TCP socket connection.
</P><HR>
<H3><b> <a name="ref0"></a><a name="TCPSocket">TCPSocket</a>(<a href="InetAddress.html">InetAddress</a> &bind, short port, int backlog) </b><code>[public]</code></H3>
<p>A TCP "server" is created as a TCP socket that is bound
to a hardware address and port number on the local machine
and that has a backlog queue to listen for remote connection
requests. If the server cannot be created, an exception is
thrown.
</p><p>
</p>
<dl><dt><b>Parameters</b>:<dd>
<table width="100%" border="0">
<tr><td align="left" valign="top">
backlog</td><td align="left" valign="top">
size of connection request queue.</td></tr>
<tr><td align="left" valign="top">
port</td><td align="left" valign="top">
number to bind socket under.</td></tr>
<tr><td align="left" valign="top">
bind</td><td align="left" valign="top">
local ip address or interface to use.</td></tr>
</table>
</dl>
<H3><b> <a name="ref1"></a><a name="TCPSocket">TCPSocket</a>(<a href="InetHostAddress.html">InetHostAddress</a> &host, short port) </b><code>[public]</code></H3>
<p>Create and connect a TCP socket to a bound TCP "server"
on a specified host bound to a specified port number. If
the socket cannot be connected, an exception is thrown.
</p><p>
</p>
<dl><dt><b>Parameters</b>:<dd>
<table width="100%" border="0">
<tr><td align="left" valign="top">
port</td><td align="left" valign="top">
number on the host to connect through.</td></tr>
<tr><td align="left" valign="top">
host</td><td align="left" valign="top">
address of internet host to connect with.</td></tr>
</table>
</dl>
<H3><b> <a name="ref2"></a><a name="TCPSocket">TCPSocket</a>(<a href="TCPSocket.html">TCPSocket</a> &server) </b><code>[public]</code></H3>
<p>Create a TCP socket that is an "accepted" client connection
from a TCP socket that has been bound as a server. This new
socket is directly connected to the remote socket that had
made a connection "request" into the servers backlog queue
and can be thought of as being the APE method of performing
an "accept()" call.
</p><p>
</p>
<dl><dt><b>Parameters</b>:<dd>
<table width="100%" border="0">
<tr><td align="left" valign="top">
server</td><td align="left" valign="top">
socket to accept connection from.</td></tr>
</table>
</dl>
<H3><b> <a name="ref3"></a><a name="TCPSocket">TCPSocket</a>(<a href="TCPSocket.html">TCPSocket</a> *server) </b><code>[public]</code></H3>
<p>Alternately create a TCP socket that is "accepted" from a
casted pointer to a TCPSocket derived object acting as a
bound TCP server. This new socket is directly connected to
the remote socket that had made a connection "request" into
the servers backlog queue.
</p><p>
</p>
<dl><dt><b>Parameters</b>:<dd>
<table width="100%" border="0">
<tr><td align="left" valign="top">
server</td><td align="left" valign="top">
pointer to accept connection from.</td></tr>
</table>
</dl>
<H3><b> <a name="ref4"></a><a name="TCPSocket">TCPSocket</a>(void) </b><code>[public]</code></H3>
<p>Create an unconnected TCP socket. Mostly for internal use.
</p>
<H3><b>bool <a name="ref5"></a><a name="OnAccept">OnAccept</a>(<a href="InetHostAddress.html">InetHostAddress</a> ia, short port) </b><code>[public virtual]</code></H3>
<p>A method to call in a derived TCPSocket class that is acting
as a server when a connection request is being accepted. The
server can implement protocol specific rules to exclude the
remote socket from being accepted by returning false. The
Peek method can also be used for this purpose.
</p><p>
</p>
<dl><dt><b>Parameters</b>:<dd>
<table width="100%" border="0">
<tr><td align="left" valign="top">
ia</td><td align="left" valign="top">
internet host address of the client.</td></tr>
<tr><td align="left" valign="top">
port</td><td align="left" valign="top">
number of the client.</td></tr>
</table>
</dl>
<dl><dt><b>Returns</b>:<dd>
true if client should be accepted.</dl>
<H3><b>int <a name="ref6"></a><a name="Readline">Readline</a>(char *buf, size_t max) </b><code>[public]</code></H3>
<p>Many TCP protocols involve the use of line oriented commands
and data. The TCP readline method provides a very effecient
means to read a single line of input from a TCP socket. This
method does not use external buffering and is presumed safe
from buffer overruns.
</p><p>
@len maximum number of bytes to read.
</p>
<dl><dt><b>Parameters</b>:<dd>
<table width="100%" border="0">
<tr><td align="left" valign="top">
buf</td><td align="left" valign="top">
pointer to buffer.</td></tr>
</table>
</dl>
<dl><dt><b>Returns</b>:<dd>
number of bytes read on success, -1 on error.</dl>
<H3><b><a href="InetHostAddress.html">InetHostAddress</a> <a name="ref7"></a><a name="getHost">getHost</a>(short *port = NULL) </b><code>[public]</code></H3>
<p>Get the local socket address and port that the current socket
has been bound to.
</p><p>
</p>
<dl><dt><b>Parameters</b>:<dd>
<table width="100%" border="0">
<tr><td align="left" valign="top">
port</td><td align="left" valign="top">
pointer to store the port number socket uses.</td></tr>
</table>
</dl>
<dl><dt><b>Returns</b>:<dd>
internet address of host interface for this socket.</dl>
<H3><b><a href="InetHostAddress.html">InetHostAddress</a> <a name="ref8"></a><a name="getPeer">getPeer</a>(short *port = NULL) </b><code>[public]</code></H3>
<p>Get the socket address of the remote socket that this socket
is currently connected to.
</p><p>
</p>
<dl><dt><b>Parameters</b>:<dd>
<table width="100%" border="0">
<tr><td align="left" valign="top">
port</td><td align="left" valign="top">
pointer to store the port number of the remote socket.</td></tr>
</table>
</dl>
<dl><dt><b>Returns</b>:<dd>
internet address of remote internet host.</dl>
<HR>
<TABLE WIDTH="100%"><TR><TD ALIGN="left" VALIGN="top">
<UL><LI><I>Author</I>: David Sugar <dyfet@tycho.com> </LI>
<LI>Documentation generated by dyfet@home.sys on Thu Dec 16 09:54:26 EST 1999
</LI>
</UL></TD><TD ALIGN="RIGHT" VALIGN="TOP">
<b>K</b><i>doc</i>
</TD>
</TR></TABLE></BODY></HTML>
|