summaryrefslogtreecommitdiff
path: root/doc/html/classSocket.html
blob: a0a55870c299cfdcfc6cb94ef95a62f411b167b4 (plain) (blame)
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
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html><head><meta http-equiv="Content-Type" content="text/html;charset=iso-8859-1">
<title>anytun: Socket Class Reference</title>
<link href="doxygen.css" rel="stylesheet" type="text/css">
<link href="tabs.css" rel="stylesheet" type="text/css">
</head><body>
<!-- Generated by Doxygen 1.5.1 -->
<div class="tabs">
  <ul>
    <li><a href="main.html"><span>Main&nbsp;Page</span></a></li>
    <li><a href="namespaces.html"><span>Namespaces</span></a></li>
    <li id="current"><a href="annotated.html"><span>Classes</span></a></li>
    <li><a href="files.html"><span>Files</span></a></li>
  </ul></div>
<div class="tabs">
  <ul>
    <li><a href="annotated.html"><span>Class&nbsp;List</span></a></li>
    <li><a href="hierarchy.html"><span>Class&nbsp;Hierarchy</span></a></li>
    <li><a href="functions.html"><span>Class&nbsp;Members</span></a></li>
  </ul></div>
<h1>Socket Class Reference</h1><!-- doxytag: class="Socket" --><code>#include &lt;<a class="el" href="PracticalSocket_8h-source.html">PracticalSocket.h</a>&gt;</code>
<p>
<p>Inheritance diagram for Socket:
<p><center><img src="classSocket.png" usemap="#Socket_map" border="0" alt=""></center>
<map name="Socket_map">
<area href="classCommunicatingSocket.html" alt="CommunicatingSocket" shape="rect" coords="72,56,207,80">
<area href="classTCPServerSocket.html" alt="TCPServerSocket" shape="rect" coords="217,56,352,80">
<area href="classTCPSocket.html" alt="TCPSocket" shape="rect" coords="0,112,135,136">
<area href="classUDPSocket.html" alt="UDPSocket" shape="rect" coords="145,112,280,136">
<area href="classUDPPacketSource.html" alt="UDPPacketSource" shape="rect" coords="145,168,280,192">
</map>
<a href="classSocket-members.html">List of all members.</a><table border="0" cellpadding="0" cellspacing="0">
<tr><td></td></tr>
<tr><td colspan="2"><br><h2>Public Member Functions</h2></td></tr>
<tr><td class="memItemLeft" nowrap align="right" valign="top">&nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="classSocket.html#eac4eb6379a543d38ed88977d3b6630a">~Socket</a> ()</td></tr>

<tr><td class="memItemLeft" nowrap align="right" valign="top">string&nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="classSocket.html#0fca07bdfa97874fba1a17995ed7cda3">getLocalAddress</a> ()  throw (SocketException)</td></tr>

<tr><td class="memItemLeft" nowrap align="right" valign="top">unsigned short&nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="classSocket.html#e01143b667d69483a2f53d0f4ce7eeed">getLocalPort</a> ()  throw (SocketException)</td></tr>

<tr><td class="memItemLeft" nowrap align="right" valign="top">void&nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="classSocket.html#773fe4a35146002de76952e16fdebcfa">setLocalPort</a> (unsigned short localPort)  throw (SocketException)</td></tr>

<tr><td class="memItemLeft" nowrap align="right" valign="top">void&nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="classSocket.html#a6b986410bc2e606ba27d01fa7cb8836">setLocalAddressAndPort</a> (const string &amp;localAddress, unsigned short localPort=0)  throw (SocketException)</td></tr>

<tr><td colspan="2"><br><h2>Static Public Member Functions</h2></td></tr>
<tr><td class="memItemLeft" nowrap align="right" valign="top">static void&nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="classSocket.html#c5060aeb501044044351d5a85b3fc95f">cleanUp</a> ()  throw (SocketException)</td></tr>

<tr><td class="memItemLeft" nowrap align="right" valign="top">static unsigned short&nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="classSocket.html#982c63b25c5b756321a74074a275adbc">resolveService</a> (const string &amp;service, const string &amp;protocol=&quot;tcp&quot;)</td></tr>

<tr><td colspan="2"><br><h2>Protected Member Functions</h2></td></tr>
<tr><td class="memItemLeft" nowrap align="right" valign="top">&nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="classSocket.html#53e00027bab2125a2b407914c6148589">Socket</a> (int type, int protocol)  throw (SocketException)</td></tr>

<tr><td class="memItemLeft" nowrap align="right" valign="top">&nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="classSocket.html#6a2609eef6559336a595a336f138d395">Socket</a> (int <a class="el" href="classSocket.html#d5704d2fdfb062139e1f88831617bbfb">sockDesc</a>)</td></tr>

<tr><td colspan="2"><br><h2>Protected Attributes</h2></td></tr>
<tr><td class="memItemLeft" nowrap align="right" valign="top">int&nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="classSocket.html#d5704d2fdfb062139e1f88831617bbfb">sockDesc</a></td></tr>

<tr><td colspan="2"><br><h2>Private Member Functions</h2></td></tr>
<tr><td class="memItemLeft" nowrap align="right" valign="top">&nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="classSocket.html#656389d58fa00729ff70c4e159623f5c">Socket</a> (const <a class="el" href="classSocket.html">Socket</a> &amp;sock)</td></tr>

<tr><td class="memItemLeft" nowrap align="right" valign="top">void&nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="classSocket.html#1ef8f4c222c32756c8b1537323702df8">operator=</a> (const <a class="el" href="classSocket.html">Socket</a> &amp;sock)</td></tr>

</table>
<hr><a name="_details"></a><h2>Detailed Description</h2>
Base class representing basic communication endpoint 
<p>
<hr><h2>Constructor &amp; Destructor Documentation</h2>
<a class="anchor" name="eac4eb6379a543d38ed88977d3b6630a"></a><!-- doxytag: member="Socket::~Socket" ref="eac4eb6379a543d38ed88977d3b6630a" args="()" -->
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">Socket::~Socket           </td>
          <td>(</td>
          <td class="paramname">          </td>
          <td>&nbsp;)&nbsp;</td>
          <td width="100%"></td>
        </tr>
      </table>
</div>
<div class="memdoc">

<p>
Close and deallocate this socket 
</div>
</div><p>
<a class="anchor" name="656389d58fa00729ff70c4e159623f5c"></a><!-- doxytag: member="Socket::Socket" ref="656389d58fa00729ff70c4e159623f5c" args="(const Socket &amp;sock)" -->
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">Socket::Socket           </td>
          <td>(</td>
          <td class="paramtype">const <a class="el" href="classSocket.html">Socket</a> &amp;&nbsp;</td>
          <td class="paramname"> <em>sock</em>          </td>
          <td>&nbsp;)&nbsp;</td>
          <td width="100%"><code> [private]</code></td>
        </tr>
      </table>
</div>
<div class="memdoc">

<p>

</div>
</div><p>
<a class="anchor" name="53e00027bab2125a2b407914c6148589"></a><!-- doxytag: member="Socket::Socket" ref="53e00027bab2125a2b407914c6148589" args="(int type, int protocol)" -->
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">Socket::Socket           </td>
          <td>(</td>
          <td class="paramtype">int&nbsp;</td>
          <td class="paramname"> <em>type</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">int&nbsp;</td>
          <td class="paramname"> <em>protocol</em></td><td>&nbsp;</td>
        </tr>
        <tr>
          <td></td>
          <td>)</td>
          <td></td><td></td><td width="100%">  throw (<a class="el" href="classSocketException.html">SocketException</a>)<code> [protected]</code></td>
        </tr>
      </table>
</div>
<div class="memdoc">

<p>

</div>
</div><p>
<a class="anchor" name="6a2609eef6559336a595a336f138d395"></a><!-- doxytag: member="Socket::Socket" ref="6a2609eef6559336a595a336f138d395" args="(int sockDesc)" -->
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">Socket::Socket           </td>
          <td>(</td>
          <td class="paramtype">int&nbsp;</td>
          <td class="paramname"> <em>sockDesc</em>          </td>
          <td>&nbsp;)&nbsp;</td>
          <td width="100%"><code> [protected]</code></td>
        </tr>
      </table>
</div>
<div class="memdoc">

<p>

</div>
</div><p>
<hr><h2>Member Function Documentation</h2>
<a class="anchor" name="0fca07bdfa97874fba1a17995ed7cda3"></a><!-- doxytag: member="Socket::getLocalAddress" ref="0fca07bdfa97874fba1a17995ed7cda3" args="()" -->
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">string Socket::getLocalAddress           </td>
          <td>(</td>
          <td class="paramname">          </td>
          <td>&nbsp;)&nbsp;</td>
          <td width="100%">  throw (<a class="el" href="classSocketException.html">SocketException</a>)</td>
        </tr>
      </table>
</div>
<div class="memdoc">

<p>
Get the local address <dl class="return" compact><dt><b>Returns:</b></dt><dd>local address of socket </dd></dl>
<dl compact><dt><b>Exceptions:</b></dt><dd>
  <table border="0" cellspacing="2" cellpadding="0">
    <tr><td valign="top"></td><td valign="top"><em><a class="el" href="classSocketException.html">SocketException</a></em>&nbsp;</td><td>thrown if fetch fails </td></tr>
  </table>
</dl>

</div>
</div><p>
<a class="anchor" name="e01143b667d69483a2f53d0f4ce7eeed"></a><!-- doxytag: member="Socket::getLocalPort" ref="e01143b667d69483a2f53d0f4ce7eeed" args="()" -->
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">unsigned short Socket::getLocalPort           </td>
          <td>(</td>
          <td class="paramname">          </td>
          <td>&nbsp;)&nbsp;</td>
          <td width="100%">  throw (<a class="el" href="classSocketException.html">SocketException</a>)</td>
        </tr>
      </table>
</div>
<div class="memdoc">

<p>
Get the local port <dl class="return" compact><dt><b>Returns:</b></dt><dd>local port of socket </dd></dl>
<dl compact><dt><b>Exceptions:</b></dt><dd>
  <table border="0" cellspacing="2" cellpadding="0">
    <tr><td valign="top"></td><td valign="top"><em><a class="el" href="classSocketException.html">SocketException</a></em>&nbsp;</td><td>thrown if fetch fails </td></tr>
  </table>
</dl>

</div>
</div><p>
<a class="anchor" name="773fe4a35146002de76952e16fdebcfa"></a><!-- doxytag: member="Socket::setLocalPort" ref="773fe4a35146002de76952e16fdebcfa" args="(unsigned short localPort)" -->
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">void Socket::setLocalPort           </td>
          <td>(</td>
          <td class="paramtype">unsigned short&nbsp;</td>
          <td class="paramname"> <em>localPort</em>          </td>
          <td>&nbsp;)&nbsp;</td>
          <td width="100%">  throw (<a class="el" href="classSocketException.html">SocketException</a>)</td>
        </tr>
      </table>
</div>
<div class="memdoc">

<p>
Set the local port to the specified port and the local address to any interface <dl compact><dt><b>Parameters:</b></dt><dd>
  <table border="0" cellspacing="2" cellpadding="0">
    <tr><td valign="top"></td><td valign="top"><em>localPort</em>&nbsp;</td><td>local port </td></tr>
  </table>
</dl>
<dl compact><dt><b>Exceptions:</b></dt><dd>
  <table border="0" cellspacing="2" cellpadding="0">
    <tr><td valign="top"></td><td valign="top"><em><a class="el" href="classSocketException.html">SocketException</a></em>&nbsp;</td><td>thrown if setting local port fails </td></tr>
  </table>
</dl>

</div>
</div><p>
<a class="anchor" name="a6b986410bc2e606ba27d01fa7cb8836"></a><!-- doxytag: member="Socket::setLocalAddressAndPort" ref="a6b986410bc2e606ba27d01fa7cb8836" args="(const string &amp;localAddress, unsigned short localPort=0)" -->
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">void Socket::setLocalAddressAndPort           </td>
          <td>(</td>
          <td class="paramtype">const string &amp;&nbsp;</td>
          <td class="paramname"> <em>localAddress</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">unsigned short&nbsp;</td>
          <td class="paramname"> <em>localPort</em> = <code>0</code></td><td>&nbsp;</td>
        </tr>
        <tr>
          <td></td>
          <td>)</td>
          <td></td><td></td><td width="100%">  throw (<a class="el" href="classSocketException.html">SocketException</a>)</td>
        </tr>
      </table>
</div>
<div class="memdoc">

<p>
Set the local port to the specified port and the local address to the specified address. If you omit the port, a random port will be selected. <dl compact><dt><b>Parameters:</b></dt><dd>
  <table border="0" cellspacing="2" cellpadding="0">
    <tr><td valign="top"></td><td valign="top"><em>localAddress</em>&nbsp;</td><td>local address </td></tr>
    <tr><td valign="top"></td><td valign="top"><em>localPort</em>&nbsp;</td><td>local port </td></tr>
  </table>
</dl>
<dl compact><dt><b>Exceptions:</b></dt><dd>
  <table border="0" cellspacing="2" cellpadding="0">
    <tr><td valign="top"></td><td valign="top"><em><a class="el" href="classSocketException.html">SocketException</a></em>&nbsp;</td><td>thrown if setting local port or address fails </td></tr>
  </table>
</dl>

</div>
</div><p>
<a class="anchor" name="c5060aeb501044044351d5a85b3fc95f"></a><!-- doxytag: member="Socket::cleanUp" ref="c5060aeb501044044351d5a85b3fc95f" args="()" -->
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">void Socket::cleanUp           </td>
          <td>(</td>
          <td class="paramname">          </td>
          <td>&nbsp;)&nbsp;</td>
          <td width="100%">  throw (<a class="el" href="classSocketException.html">SocketException</a>)<code> [static]</code></td>
        </tr>
      </table>
</div>
<div class="memdoc">

<p>
If WinSock, unload the WinSock DLLs; otherwise do nothing. We ignore this in our sample client code but include it in the library for completeness. If you are running on Windows and you are concerned about DLL resource consumption, call this after you are done with all <a class="el" href="classSocket.html">Socket</a> instances. If you execute this on Windows while some instance of <a class="el" href="classSocket.html">Socket</a> exists, you are toast. For portability of client code, this is an empty function on non-Windows platforms so you can always include it. <dl compact><dt><b>Parameters:</b></dt><dd>
  <table border="0" cellspacing="2" cellpadding="0">
    <tr><td valign="top"></td><td valign="top"><em>buffer</em>&nbsp;</td><td>buffer to receive the data </td></tr>
    <tr><td valign="top"></td><td valign="top"><em>bufferLen</em>&nbsp;</td><td>maximum number of bytes to read into buffer </td></tr>
  </table>
</dl>
<dl class="return" compact><dt><b>Returns:</b></dt><dd>number of bytes read, 0 for EOF, and -1 for error </dd></dl>
<dl compact><dt><b>Exceptions:</b></dt><dd>
  <table border="0" cellspacing="2" cellpadding="0">
    <tr><td valign="top"></td><td valign="top"><em><a class="el" href="classSocketException.html">SocketException</a></em>&nbsp;</td><td>thrown WinSock clean up fails </td></tr>
  </table>
</dl>

</div>
</div><p>
<a class="anchor" name="982c63b25c5b756321a74074a275adbc"></a><!-- doxytag: member="Socket::resolveService" ref="982c63b25c5b756321a74074a275adbc" args="(const string &amp;service, const string &amp;protocol=&quot;tcp&quot;)" -->
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">unsigned short Socket::resolveService           </td>
          <td>(</td>
          <td class="paramtype">const string &amp;&nbsp;</td>
          <td class="paramname"> <em>service</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">const string &amp;&nbsp;</td>
          <td class="paramname"> <em>protocol</em> = <code>&quot;tcp&quot;</code></td><td>&nbsp;</td>
        </tr>
        <tr>
          <td></td>
          <td>)</td>
          <td></td><td></td><td width="100%"><code> [static]</code></td>
        </tr>
      </table>
</div>
<div class="memdoc">

<p>
Resolve the specified service for the specified protocol to the corresponding port number in host byte order <dl compact><dt><b>Parameters:</b></dt><dd>
  <table border="0" cellspacing="2" cellpadding="0">
    <tr><td valign="top"></td><td valign="top"><em>service</em>&nbsp;</td><td>service to resolve (e.g., "http") </td></tr>
    <tr><td valign="top"></td><td valign="top"><em>protocol</em>&nbsp;</td><td>protocol of service to resolve. Default is "tcp". </td></tr>
  </table>
</dl>

</div>
</div><p>
<a class="anchor" name="1ef8f4c222c32756c8b1537323702df8"></a><!-- doxytag: member="Socket::operator=" ref="1ef8f4c222c32756c8b1537323702df8" args="(const Socket &amp;sock)" -->
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">void Socket::operator=           </td>
          <td>(</td>
          <td class="paramtype">const <a class="el" href="classSocket.html">Socket</a> &amp;&nbsp;</td>
          <td class="paramname"> <em>sock</em>          </td>
          <td>&nbsp;)&nbsp;</td>
          <td width="100%"><code> [private]</code></td>
        </tr>
      </table>
</div>
<div class="memdoc">

<p>

</div>
</div><p>
<hr><h2>Member Data Documentation</h2>
<a class="anchor" name="d5704d2fdfb062139e1f88831617bbfb"></a><!-- doxytag: member="Socket::sockDesc" ref="d5704d2fdfb062139e1f88831617bbfb" args="" -->
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">int <a class="el" href="classSocket.html#d5704d2fdfb062139e1f88831617bbfb">Socket::sockDesc</a><code> [protected]</code>          </td>
        </tr>
      </table>
</div>
<div class="memdoc">

<p>

</div>
</div><p>
<hr>The documentation for this class was generated from the following files:<ul>
<li><a class="el" href="PracticalSocket_8h-source.html">PracticalSocket.h</a><li><a class="el" href="PracticalSocket_8cpp.html">PracticalSocket.cpp</a></ul>
<hr size="1"><address style="align: right;"><small>Generated on Mon Dec 3 11:49:25 2007 for anytun by&nbsp;
<a href="http://www.doxygen.org/index.html">
<img src="doxygen.png" alt="doxygen" align="middle" border="0"></a> 1.5.1 </small></address>
</body>
</html>