mirror of
https://github.com/thestk/stk
synced 2026-01-12 04:21:52 +00:00
248 lines
14 KiB
HTML
248 lines
14 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"> <img src="ccrma.gif"> <img src="mcgill.gif"><P>
|
|
<a class="qindex" href="index.html">Home</a> <a class="qindex" href="information.html">Information</a> <a class="qindex" href="classes.html">Classes</a> <a class="qindex" href="download.html">Download</a> <a class="qindex" href="usage.html">Usage</a> <a class="qindex" href="maillist.html">Mail List</a> <a class="qindex" href="system.html">Requirements</a> <a class="qindex" href="links.html">Links</a> <a class="qindex" href="tutorial.html">Tutorial</a></CENTER>
|
|
<HR>
|
|
<!-- Generated by Doxygen 1.3.4 -->
|
|
<h1>Socket Class Reference</h1>STK TCP socket client/server class.
|
|
<a href="#_details">More...</a>
|
|
<p>
|
|
<code>#include <<a class="el" href="Socket_8h-source.html">Socket.h</a>></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="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></td></tr>
|
|
<tr><td colspan=2><br><h2>Public Member Functions</h2></td></tr>
|
|
<tr><td class="memItemLeft" nowrap align=right valign=top> </td><td class="memItemRight" valign=bottom><a class="el" href="classSocket.html#a0">Socket</a> (int port=2006)</td></tr>
|
|
|
|
<tr><td class="mdescLeft"> </td><td class="mdescRight">Default constructor which creates a local socket server on port 2006 (or the specified port number). </em> <a href="#a0"></a><em><br><br></td></tr>
|
|
<tr><td class="memItemLeft" nowrap align=right valign=top> </td><td class="memItemRight" valign=bottom><a class="el" href="classSocket.html#a1">Socket</a> (int port, const char *hostname)</td></tr>
|
|
|
|
<tr><td class="mdescLeft"> </td><td class="mdescRight">Class constructor which creates a socket client connection to the specified host and port. </em> <a href="#a1"></a><em><br><br></td></tr>
|
|
<tr><td class="memItemLeft" nowrap align=right valign=top><a class="anchor" name="a2" doxytag="Socket::~Socket" ></a>
|
|
</td><td class="memItemRight" valign=bottom><a class="el" href="classSocket.html#a2">~Socket</a> ()</td></tr>
|
|
|
|
<tr><td class="mdescLeft"> </td><td class="mdescRight">The class destructor closes the socket instance, breaking any existing connections. <br><br></td></tr>
|
|
<tr><td class="memItemLeft" nowrap align=right valign=top>int </td><td class="memItemRight" valign=bottom><a class="el" href="classSocket.html#a3">connect</a> (int port, const char *hostname="localhost")</td></tr>
|
|
|
|
<tr><td class="mdescLeft"> </td><td class="mdescRight">Connect a socket client to the specified host and port and returns the resulting socket descriptor. </em> <a href="#a3"></a><em><br><br></td></tr>
|
|
<tr><td class="memItemLeft" nowrap align=right valign=top><a class="anchor" name="a4" doxytag="Socket::close" ></a>
|
|
void </td><td class="memItemRight" valign=bottom><a class="el" href="classSocket.html#a4">close</a> (void)</td></tr>
|
|
|
|
<tr><td class="mdescLeft"> </td><td class="mdescRight">Close this socket. <br><br></td></tr>
|
|
<tr><td class="memItemLeft" nowrap align=right valign=top><a class="anchor" name="a5" doxytag="Socket::socket" ></a>
|
|
int </td><td class="memItemRight" valign=bottom><a class="el" href="classSocket.html#a5">socket</a> (void) const </td></tr>
|
|
|
|
<tr><td class="mdescLeft"> </td><td class="mdescRight">Return the server/client socket descriptor. <br><br></td></tr>
|
|
<tr><td class="memItemLeft" nowrap align=right valign=top><a class="anchor" name="a6" doxytag="Socket::port" ></a>
|
|
int </td><td class="memItemRight" valign=bottom><a class="el" href="classSocket.html#a6">port</a> (void) const </td></tr>
|
|
|
|
<tr><td class="mdescLeft"> </td><td class="mdescRight">Return the server/client port number. <br><br></td></tr>
|
|
<tr><td class="memItemLeft" nowrap align=right valign=top>int </td><td class="memItemRight" valign=bottom><a class="el" href="classSocket.html#a7">accept</a> (void)</td></tr>
|
|
|
|
<tr><td class="mdescLeft"> </td><td class="mdescRight">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"></a><em><br><br></td></tr>
|
|
<tr><td class="memItemLeft" nowrap align=right valign=top><a class="anchor" name="a8" doxytag="Socket::writeBuffer" ></a>
|
|
int </td><td class="memItemRight" valign=bottom><a class="el" href="classSocket.html#a8">writeBuffer</a> (const void *buffer, long bufferSize, int flags=0)</td></tr>
|
|
|
|
<tr><td class="mdescLeft"> </td><td class="mdescRight">Write a buffer over the socket connection. Returns the number of bytes written or -1 if an error occurs. <br><br></td></tr>
|
|
<tr><td class="memItemLeft" nowrap align=right valign=top><a class="anchor" name="a9" doxytag="Socket::readBuffer" ></a>
|
|
int </td><td class="memItemRight" valign=bottom><a class="el" href="classSocket.html#a9">readBuffer</a> (void *buffer, long bufferSize, int flags=0)</td></tr>
|
|
|
|
<tr><td class="mdescLeft"> </td><td class="mdescRight">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. <br><br></td></tr>
|
|
<tr><td colspan=2><br><h2>Static Public Member Functions</h2></td></tr>
|
|
<tr><td class="memItemLeft" nowrap align=right valign=top><a class="anchor" name="e0" doxytag="Socket::setBlocking" ></a>
|
|
void </td><td class="memItemRight" valign=bottom><a class="el" href="classSocket.html#e0">setBlocking</a> (int socket, bool enable)</td></tr>
|
|
|
|
<tr><td class="mdescLeft"> </td><td class="mdescRight">If enable = false, the socket is set to non-blocking mode. When first created, sockets are by default in blocking mode. <br><br></td></tr>
|
|
<tr><td class="memItemLeft" nowrap align=right valign=top><a class="anchor" name="e1" doxytag="Socket::close" ></a>
|
|
void </td><td class="memItemRight" valign=bottom><a class="el" href="classSocket.html#e1">close</a> (int socket)</td></tr>
|
|
|
|
<tr><td class="mdescLeft"> </td><td class="mdescRight">Close the socket with the given descriptor. <br><br></td></tr>
|
|
<tr><td class="memItemLeft" nowrap align=right valign=top><a class="anchor" name="e2" doxytag="Socket::isValid" ></a>
|
|
bool </td><td class="memItemRight" valign=bottom><a class="el" href="classSocket.html#e2">isValid</a> (int socket)</td></tr>
|
|
|
|
<tr><td class="mdescLeft"> </td><td class="mdescRight">Returns TRUE is the socket descriptor is valid. <br><br></td></tr>
|
|
<tr><td class="memItemLeft" nowrap align=right valign=top><a class="anchor" name="e3" doxytag="Socket::writeBuffer" ></a>
|
|
int </td><td class="memItemRight" valign=bottom><a class="el" href="classSocket.html#e3">writeBuffer</a> (int socket, const void *buffer, long bufferSize, int flags)</td></tr>
|
|
|
|
<tr><td class="mdescLeft"> </td><td class="mdescRight">Write a buffer via the specified socket. Returns the number of bytes written or -1 if an error occurs. <br><br></td></tr>
|
|
<tr><td class="memItemLeft" nowrap align=right valign=top><a class="anchor" name="e4" doxytag="Socket::readBuffer" ></a>
|
|
int </td><td class="memItemRight" valign=bottom><a class="el" href="classSocket.html#e4">readBuffer</a> (int socket, void *buffer, long bufferSize, int flags)</td></tr>
|
|
|
|
<tr><td class="mdescLeft"> </td><td class="mdescRight">Read a buffer via the specified socket. Returns the number of bytes read or -1 if an error occurs. <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>
|
|
|
|
<p>
|
|
Definition at line <a class="el" href="Socket_8h-source.html#l00026">26</a> of file <a class="el" href="Socket_8h-source.html">Socket.h</a>.<hr><h2>Constructor & Destructor Documentation</h2>
|
|
<a class="anchor" name="a0" doxytag="Socket::Socket" ></a><p>
|
|
<table class="mdTable" width="100%" cellpadding="2" cellspacing="0">
|
|
<tr>
|
|
<td class="mdRow">
|
|
<table cellpadding="0" cellspacing="0" border="0">
|
|
<tr>
|
|
<td class="md" nowrap valign="top"> Socket::Socket </td>
|
|
<td class="md" valign="top">( </td>
|
|
<td class="md" nowrap valign="top">int </td>
|
|
<td class="mdname1" valign="top" nowrap> <em>port</em> = 2006 </td>
|
|
<td class="md" valign="top"> ) </td>
|
|
<td class="md" nowrap></td>
|
|
</tr>
|
|
|
|
</table>
|
|
</td>
|
|
</tr>
|
|
</table>
|
|
<table cellspacing=5 cellpadding=0 border=0>
|
|
<tr>
|
|
<td>
|
|
|
|
</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 class="anchor" name="a1" doxytag="Socket::Socket" ></a><p>
|
|
<table class="mdTable" width="100%" cellpadding="2" cellspacing="0">
|
|
<tr>
|
|
<td class="mdRow">
|
|
<table cellpadding="0" cellspacing="0" border="0">
|
|
<tr>
|
|
<td class="md" nowrap valign="top"> Socket::Socket </td>
|
|
<td class="md" valign="top">( </td>
|
|
<td class="md" nowrap valign="top">int </td>
|
|
<td class="mdname" nowrap> <em>port</em>, </td>
|
|
</tr>
|
|
<tr>
|
|
<td></td>
|
|
<td></td>
|
|
<td class="md" nowrap>const char * </td>
|
|
<td class="mdname" nowrap> <em>hostname</em></td>
|
|
</tr>
|
|
<tr>
|
|
<td></td>
|
|
<td class="md">) </td>
|
|
<td class="md" colspan="2"></td>
|
|
</tr>
|
|
|
|
</table>
|
|
</td>
|
|
</tr>
|
|
</table>
|
|
<table cellspacing=5 cellpadding=0 border=0>
|
|
<tr>
|
|
<td>
|
|
|
|
</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 class="anchor" name="a3" doxytag="Socket::connect" ></a><p>
|
|
<table class="mdTable" width="100%" cellpadding="2" cellspacing="0">
|
|
<tr>
|
|
<td class="mdRow">
|
|
<table cellpadding="0" cellspacing="0" border="0">
|
|
<tr>
|
|
<td class="md" nowrap valign="top"> int Socket::connect </td>
|
|
<td class="md" valign="top">( </td>
|
|
<td class="md" nowrap valign="top">int </td>
|
|
<td class="mdname" nowrap> <em>port</em>, </td>
|
|
</tr>
|
|
<tr>
|
|
<td></td>
|
|
<td></td>
|
|
<td class="md" nowrap>const char * </td>
|
|
<td class="mdname" nowrap> <em>hostname</em> = "localhost"</td>
|
|
</tr>
|
|
<tr>
|
|
<td></td>
|
|
<td class="md">) </td>
|
|
<td class="md" colspan="2"></td>
|
|
</tr>
|
|
|
|
</table>
|
|
</td>
|
|
</tr>
|
|
</table>
|
|
<table cellspacing=5 cellpadding=0 border=0>
|
|
<tr>
|
|
<td>
|
|
|
|
</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></dt><dd><a class="el" href="classSocket.html#a7">accept</a> </dd></dl>
|
|
</td>
|
|
</tr>
|
|
</table>
|
|
<a class="anchor" name="a7" doxytag="Socket::accept" ></a><p>
|
|
<table class="mdTable" width="100%" cellpadding="2" cellspacing="0">
|
|
<tr>
|
|
<td class="mdRow">
|
|
<table cellpadding="0" cellspacing="0" border="0">
|
|
<tr>
|
|
<td class="md" nowrap valign="top"> int Socket::accept </td>
|
|
<td class="md" valign="top">( </td>
|
|
<td class="md" nowrap valign="top">void </td>
|
|
<td class="mdname1" valign="top" nowrap> </td>
|
|
<td class="md" valign="top"> ) </td>
|
|
<td class="md" nowrap></td>
|
|
</tr>
|
|
|
|
</table>
|
|
</td>
|
|
</tr>
|
|
</table>
|
|
<table cellspacing=5 cellpadding=0 border=0>
|
|
<tr>
|
|
<td>
|
|
|
|
</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>©1995-2004 Perry R. Cook and Gary P. Scavone. All Rights Reserved.</td></tr>
|
|
</table>
|
|
|
|
</BODY>
|
|
</HTML>
|