Files
stk/doc/html/classSocket.html
2013-09-29 23:33:56 +02:00

227 lines
12 KiB
HTML

<HTML>
<HEAD>
<TITLE>The Synthesis ToolKit in C++ (STK)</TITLE>
<LINK HREF="doxygen.css" REL="stylesheet" TYPE="text/css">
</HEAD>
<BODY BGCOLOR="#FFFFFF">
<CENTER>
<img src="princeton.gif"> &nbsp; <img src="ccrma.gif"><P>
<a class="qindex" href="index.html">Home</a> &nbsp; <a class="qindex" href="information.html">Information</a> &nbsp; <a class="qindex" href="classes.html">Classes</a> &nbsp; <a class="qindex" href="download.html">Download</a> &nbsp; <a class="qindex" href="usage.html">Usage</a> &nbsp; <a class="qindex" href="maillist.html">Mail List</a> &nbsp; <a class="qindex" href="system.html">Requirements</a> &nbsp; <a class="qindex" href="tutorial.html">Tutorial</a></CENTER>
<HR>
<!-- Generated by Doxygen 1.2.8.1 -->
<h1>Socket Class Reference</h1>STK TCP socket client/server class.
<a href="#_details">More...</a>
<p>
<code>#include &lt;<a class="el" href="Socket_8h-source.html">Socket.h</a>&gt;</code>
<p>
<p>Inheritance diagram for Socket::
<p><center><img src="classSocket.gif" usemap="#Socket_map" border="0"></center>
<map name="Socket_map">
<area href="classStk.html" alt="Stk" shape="rect" coords="0,0,50,24">
</map>
<a href="classSocket-members.html">List of all members.</a><table border=0 cellpadding=0 cellspacing=0>
<tr><td colspan=2><br><h2>Public Methods</h2></td></tr>
<tr><td nowrap align=right valign=top>&nbsp;</td><td valign=bottom><a class="el" href="classSocket.html#a0">Socket</a> (int port=2006)</td></tr>
<tr><td>&nbsp;</td><td><font size=-1><em>Default constructor which creates a local socket server on port 2006 (or the specified port number).</em> <a href="#a0">More...</a><em></em></font><br><br></td></tr>
<tr><td nowrap align=right valign=top>&nbsp;</td><td valign=bottom><a class="el" href="classSocket.html#a1">Socket</a> (int port, const char *hostname)</td></tr>
<tr><td>&nbsp;</td><td><font size=-1><em>Class constructor which creates a socket client connection to the specified host and port.</em> <a href="#a1">More...</a><em></em></font><br><br></td></tr>
<tr><td nowrap align=right valign=top><a name="a2" doxytag="Socket::~Socket"></a>
&nbsp;</td><td valign=bottom><a class="el" href="classSocket.html#a2">~Socket</a> ()</td></tr>
<tr><td>&nbsp;</td><td><font size=-1><em>The class destructor closes the socket instance, breaking any existing connections.</em></font><br><br></td></tr>
<tr><td nowrap align=right valign=top>int&nbsp;</td><td valign=bottom><a class="el" href="classSocket.html#a3">connect</a> (int port, const char *hostname="localhost")</td></tr>
<tr><td>&nbsp;</td><td><font size=-1><em>Connect a socket client to the specified host and port and returns the resulting socket descriptor.</em> <a href="#a3">More...</a><em></em></font><br><br></td></tr>
<tr><td nowrap align=right valign=top><a name="a4" doxytag="Socket::close"></a>
void&nbsp;</td><td valign=bottom><a class="el" href="classSocket.html#a4">close</a> (void)</td></tr>
<tr><td>&nbsp;</td><td><font size=-1><em>Close this socket.</em></font><br><br></td></tr>
<tr><td nowrap align=right valign=top><a name="a5" doxytag="Socket::socket"></a>
int&nbsp;</td><td valign=bottom><a class="el" href="classSocket.html#a5">socket</a> (void) const</td></tr>
<tr><td>&nbsp;</td><td><font size=-1><em>Return the server/client socket descriptor.</em></font><br><br></td></tr>
<tr><td nowrap align=right valign=top><a name="a6" doxytag="Socket::port"></a>
int&nbsp;</td><td valign=bottom><a class="el" href="classSocket.html#a6">port</a> (void) const</td></tr>
<tr><td>&nbsp;</td><td><font size=-1><em>Return the server/client port number.</em></font><br><br></td></tr>
<tr><td nowrap align=right valign=top>int&nbsp;</td><td valign=bottom><a class="el" href="classSocket.html#a7">accept</a> (void)</td></tr>
<tr><td>&nbsp;</td><td><font size=-1><em>If this is a socket server, extract the first pending connection request from the queue and create a new connection, returning the descriptor for the accepted socket.</em> <a href="#a7">More...</a><em></em></font><br><br></td></tr>
<tr><td nowrap align=right valign=top><a name="a8" doxytag="Socket::writeBuffer"></a>
int&nbsp;</td><td valign=bottom><a class="el" href="classSocket.html#a8">writeBuffer</a> (const void *buffer, long bufferSize, int flags=0)</td></tr>
<tr><td>&nbsp;</td><td><font size=-1><em>Write a buffer over the socket connection. Returns the number of bytes written or -1 if an error occurs.</em></font><br><br></td></tr>
<tr><td nowrap align=right valign=top><a name="a9" doxytag="Socket::readBuffer"></a>
int&nbsp;</td><td valign=bottom><a class="el" href="classSocket.html#a9">readBuffer</a> (void *buffer, long bufferSize, int flags=0)</td></tr>
<tr><td>&nbsp;</td><td><font size=-1><em>Read a buffer from the socket connection, up to length <em>bufferSize</em>. Returns the number of bytes read or -1 if an error occurs.</em></font><br><br></td></tr>
<tr><td colspan=2><br><h2>Static Public Methods</h2></td></tr>
<tr><td nowrap align=right valign=top><a name="d0" doxytag="Socket::setBlocking"></a>
void&nbsp;</td><td valign=bottom><a class="el" href="classSocket.html#d0">setBlocking</a> (int socket, bool enable)</td></tr>
<tr><td>&nbsp;</td><td><font size=-1><em>If enable = false, the socket is set to non-blocking mode. When first created, sockets are by default in blocking mode.</em></font><br><br></td></tr>
<tr><td nowrap align=right valign=top><a name="d1" doxytag="Socket::close"></a>
void&nbsp;</td><td valign=bottom><a class="el" href="classSocket.html#d1">close</a> (int socket)</td></tr>
<tr><td>&nbsp;</td><td><font size=-1><em>Close the socket with the given descriptor.</em></font><br><br></td></tr>
<tr><td nowrap align=right valign=top><a name="d2" doxytag="Socket::isValid"></a>
bool&nbsp;</td><td valign=bottom><a class="el" href="classSocket.html#d2">isValid</a> (int socket)</td></tr>
<tr><td>&nbsp;</td><td><font size=-1><em>Returns TRUE is the socket descriptor is valid.</em></font><br><br></td></tr>
<tr><td nowrap align=right valign=top><a name="d3" doxytag="Socket::writeBuffer"></a>
int&nbsp;</td><td valign=bottom><a class="el" href="classSocket.html#d3">writeBuffer</a> (int socket, const void *buffer, long bufferSize, int flags)</td></tr>
<tr><td>&nbsp;</td><td><font size=-1><em>Write a buffer via the specified socket. Returns the number of bytes written or -1 if an error occurs.</em></font><br><br></td></tr>
<tr><td nowrap align=right valign=top><a name="d4" doxytag="Socket::readBuffer"></a>
int&nbsp;</td><td valign=bottom><a class="el" href="classSocket.html#d4">readBuffer</a> (int socket, void *buffer, long bufferSize, int flags)</td></tr>
<tr><td>&nbsp;</td><td><font size=-1><em>Read a buffer via the specified socket. Returns the number of bytes read or -1 if an error occurs.</em></font><br><br></td></tr>
</table>
<hr><a name="_details"></a><h2>Detailed Description</h2>
STK TCP socket client/server class.
<p>
This class provides a uniform cross-platform TCP socket client or socket server interface. Methods are provided for reading or writing data buffers to/from connections. This class also provides a number of static functions for use with external socket descriptors.
<p>
The user is responsible for checking the values returned by the read/write methods. Values less than or equal to zero indicate a closed or lost connection or the occurence of an error.
<p>
by Perry R. Cook and Gary P. Scavone, 1995 - 2002.
<p>
<hr><h2>Constructor &amp; Destructor Documentation</h2>
<a name="a0" doxytag="Socket::Socket"></a><p>
<table width="100%" cellpadding="2" cellspacing="0" border="0">
<tr>
<td class="md">
<table cellpadding="0" cellspacing="0" border="0">
<tr>
<td nowrap valign="top"><b>
Socket::Socket (
</b></td>
<td valign="bottom"><b>
int <em>port</em> = 2006&nbsp;)
</b></td>
</tr>
</table>
</td>
</tr>
</table>
<table cellspacing=5 cellpadding=0 border=0>
<tr>
<td>
&nbsp;
</td>
<td>
<p>
Default constructor which creates a local socket server on port 2006 (or the specified port number).
<p>
An <a class="el" href="classStkError.html">StkError</a> will be thrown if a socket error occurs during instantiation. </td>
</tr>
</table>
<a name="a1" doxytag="Socket::Socket"></a><p>
<table width="100%" cellpadding="2" cellspacing="0" border="0">
<tr>
<td class="md">
<table cellpadding="0" cellspacing="0" border="0">
<tr>
<td nowrap valign="top"><b>
Socket::Socket (
</b></td>
<td valign="bottom"><b>
int <em>port</em>,
</b></td>
</tr>
<tr>
<td></td>
<td><b>
const char * <em>hostname</em>&nbsp;)
</b></td>
</tr>
</table>
</td>
</tr>
</table>
<table cellspacing=5 cellpadding=0 border=0>
<tr>
<td>
&nbsp;
</td>
<td>
<p>
Class constructor which creates a socket client connection to the specified host and port.
<p>
An <a class="el" href="classStkError.html">StkError</a> will be thrown if a socket error occurs during instantiation. </td>
</tr>
</table>
<hr><h2>Member Function Documentation</h2>
<a name="a3" doxytag="Socket::connect"></a><p>
<table width="100%" cellpadding="2" cellspacing="0" border="0">
<tr>
<td class="md">
<table cellpadding="0" cellspacing="0" border="0">
<tr>
<td nowrap valign="top"><b>
int Socket::connect (
</b></td>
<td valign="bottom"><b>
int <em>port</em>,
</b></td>
</tr>
<tr>
<td></td>
<td><b>
const char * <em>hostname</em> = "localhost"&nbsp;)
</b></td>
</tr>
</table>
</td>
</tr>
</table>
<table cellspacing=5 cellpadding=0 border=0>
<tr>
<td>
&nbsp;
</td>
<td>
<p>
Connect a socket client to the specified host and port and returns the resulting socket descriptor.
<p>
This method is valid for socket clients only. If it is called for a socket server, -1 is returned. If the socket client is already connected, that connection is terminated and a new connection is attempted. Server connections are made using the <a class="el" href="classSocket.html#a7">accept</a>() method. An <a class="el" href="classStkError.html">StkError</a> will be thrown if a socket error occurs during instantiation. <dl compact><dt>
<b>See also: </b><dd>
<a class="el" href="classSocket.html#a7">accept</a> </dl> </td>
</tr>
</table>
<a name="a7" doxytag="Socket::accept"></a><p>
<table width="100%" cellpadding="2" cellspacing="0" border="0">
<tr>
<td class="md">
<table cellpadding="0" cellspacing="0" border="0">
<tr>
<td nowrap valign="top"><b>
int Socket::accept (
</b></td>
<td valign="bottom"><b>
void&nbsp;)
</b></td>
</tr>
</table>
</td>
</tr>
</table>
<table cellspacing=5 cellpadding=0 border=0>
<tr>
<td>
&nbsp;
</td>
<td>
<p>
If this is a socket server, extract the first pending connection request from the queue and create a new connection, returning the descriptor for the accepted socket.
<p>
If no connection requests are pending and the socket has not been set non-blocking, this function will block until a connection is present. If an error occurs or this is a socket client, -1 is returned. </td>
</tr>
</table>
<hr>The documentation for this class was generated from the following file:<ul>
<li><a class="el" href="Socket_8h-source.html">Socket.h</a></ul>
<HR>
<table>
<tr><td><A HREF="http://www-ccrma.stanford.edu/software/stk/"><I>The Synthesis ToolKit in C++ (STK)</I></A></td></tr>
<tr><td>&copy;1995-2002 Perry R. Cook and Gary P. Scavone. All Rights Reserved.</td></tr>
</table>
</BODY>
</HTML>