820 lines
51 KiB
HTML
820 lines
51 KiB
HTML
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
|
<html xmlns="http://www.w3.org/1999/xhtml">
|
|
<head>
|
|
<title>SFML - Simple and Fast Multimedia Library</title>
|
|
<meta http-equiv="Content-Type" content="text/html;"/>
|
|
<meta charset="utf-8"/>
|
|
<!--<link rel='stylesheet' type='text/css' href="https://fonts.googleapis.com/css?family=Ubuntu:400,700,400italic"/>-->
|
|
<link rel="stylesheet" type="text/css" href="doxygen.css" title="default" media="screen,print" />
|
|
<script type="text/javascript" src="jquery.js"></script>
|
|
<script type="text/javascript" src="dynsections.js"></script>
|
|
</head>
|
|
<body>
|
|
<div id="banner-container">
|
|
<div id="banner">
|
|
<span id="sfml">SFML 2.5.1</span>
|
|
</div>
|
|
</div>
|
|
<div id="content">
|
|
<!-- Generated by Doxygen 1.8.14 -->
|
|
<div id="navrow1" class="tabs">
|
|
<ul class="tablist">
|
|
<li><a href="index.html"><span>Main Page</span></a></li>
|
|
<li><a href="pages.html"><span>Related Pages</span></a></li>
|
|
<li><a href="modules.html"><span>Modules</span></a></li>
|
|
<li><a href="namespaces.html"><span>Namespaces</span></a></li>
|
|
<li class="current"><a href="annotated.html"><span>Classes</span></a></li>
|
|
<li><a href="files.html"><span>Files</span></a></li>
|
|
</ul>
|
|
</div>
|
|
<div id="navrow2" class="tabs2">
|
|
<ul class="tablist">
|
|
<li><a href="annotated.html"><span>Class List</span></a></li>
|
|
<li><a href="classes.html"><span>Class Index</span></a></li>
|
|
<li><a href="hierarchy.html"><span>Class Hierarchy</span></a></li>
|
|
<li><a href="functions.html"><span>Class Members</span></a></li>
|
|
</ul>
|
|
</div>
|
|
<div id="nav-path" class="navpath">
|
|
<ul>
|
|
<li class="navelem"><b>sf</b></li><li class="navelem"><a class="el" href="classsf_1_1TcpSocket.html">TcpSocket</a></li> </ul>
|
|
</div>
|
|
</div><!-- top -->
|
|
<div class="header">
|
|
<div class="summary">
|
|
<a href="#nested-classes">Classes</a> |
|
|
<a href="#pub-types">Public Types</a> |
|
|
<a href="#pub-methods">Public Member Functions</a> |
|
|
<a href="#pro-types">Protected Types</a> |
|
|
<a href="#pro-methods">Protected Member Functions</a> |
|
|
<a href="#friends">Friends</a> |
|
|
<a href="classsf_1_1TcpSocket-members.html">List of all members</a> </div>
|
|
<div class="headertitle">
|
|
<div class="title">sf::TcpSocket Class Reference<div class="ingroups"><a class="el" href="group__network.html">Network module</a></div></div> </div>
|
|
</div><!--header-->
|
|
<div class="contents">
|
|
|
|
<p>Specialized socket using the TCP protocol.
|
|
<a href="classsf_1_1TcpSocket.html#details">More...</a></p>
|
|
|
|
<p><code>#include <<a class="el" href="TcpSocket_8hpp_source.html">TcpSocket.hpp</a>></code></p>
|
|
<div class="dynheader">
|
|
Inheritance diagram for sf::TcpSocket:</div>
|
|
<div class="dyncontent">
|
|
<div class="center">
|
|
<img src="classsf_1_1TcpSocket.png" usemap="#sf::TcpSocket_map" alt=""/>
|
|
<map id="sf::TcpSocket_map" name="sf::TcpSocket_map">
|
|
<area href="classsf_1_1Socket.html" title="Base class for all the socket types. " alt="sf::Socket" shape="rect" coords="0,56,105,80"/>
|
|
<area href="classsf_1_1NonCopyable.html" title="Utility class that makes any derived class non-copyable. " alt="sf::NonCopyable" shape="rect" coords="0,0,105,24"/>
|
|
</map>
|
|
</div></div>
|
|
<table class="memberdecls">
|
|
<tr class="heading"><td colspan="2"><h2 class="groupheader"><a name="pub-types"></a>
|
|
Public Types</h2></td></tr>
|
|
<tr class="memitem:a51bf0fd51057b98a10fbb866246176dc"><td class="memItemLeft" align="right" valign="top">enum  </td><td class="memItemRight" valign="bottom"><a class="el" href="classsf_1_1Socket.html#a51bf0fd51057b98a10fbb866246176dc">Status</a> { <br />
|
|
  <a class="el" href="classsf_1_1Socket.html#a51bf0fd51057b98a10fbb866246176dca1de3a85bc56d3ae85b3d0f3cfd04ae90">Done</a>,
|
|
<a class="el" href="classsf_1_1Socket.html#a51bf0fd51057b98a10fbb866246176dca8554848daae98f996e131bdeed076c09">NotReady</a>,
|
|
<a class="el" href="classsf_1_1Socket.html#a51bf0fd51057b98a10fbb866246176dca181c163fad2eaea927185d127c392706">Partial</a>,
|
|
<a class="el" href="classsf_1_1Socket.html#a51bf0fd51057b98a10fbb866246176dcab215141f756acdc23c67fad149710eb1">Disconnected</a>,
|
|
<br />
|
|
  <a class="el" href="classsf_1_1Socket.html#a51bf0fd51057b98a10fbb866246176dca1dc9854433a28c22e192721179a2df5d">Error</a>
|
|
<br />
|
|
}</td></tr>
|
|
<tr class="memdesc:a51bf0fd51057b98a10fbb866246176dc"><td class="mdescLeft"> </td><td class="mdescRight">Status codes that may be returned by socket functions. <a href="classsf_1_1Socket.html#a51bf0fd51057b98a10fbb866246176dc">More...</a><br /></td></tr>
|
|
<tr class="separator:a51bf0fd51057b98a10fbb866246176dc"><td class="memSeparator" colspan="2"> </td></tr>
|
|
<tr class="memitem:aa3e6c984bcb81a35234dcc9cc8369d75"><td class="memItemLeft" align="right" valign="top">enum  </td><td class="memItemRight" valign="bottom">{ <a class="el" href="classsf_1_1Socket.html#aa3e6c984bcb81a35234dcc9cc8369d75a5a3c30fd128895403afc11076f461b19">AnyPort</a> = 0
|
|
}</td></tr>
|
|
<tr class="memdesc:aa3e6c984bcb81a35234dcc9cc8369d75"><td class="mdescLeft"> </td><td class="mdescRight">Some special values used by sockets. <a href="classsf_1_1Socket.html#aa3e6c984bcb81a35234dcc9cc8369d75">More...</a><br /></td></tr>
|
|
<tr class="separator:aa3e6c984bcb81a35234dcc9cc8369d75"><td class="memSeparator" colspan="2"> </td></tr>
|
|
</table><table class="memberdecls">
|
|
<tr class="heading"><td colspan="2"><h2 class="groupheader"><a name="pub-methods"></a>
|
|
Public Member Functions</h2></td></tr>
|
|
<tr class="memitem:a62a9bf81fd7f15fedb29fd1348483236"><td class="memItemLeft" align="right" valign="top"> </td><td class="memItemRight" valign="bottom"><a class="el" href="classsf_1_1TcpSocket.html#a62a9bf81fd7f15fedb29fd1348483236">TcpSocket</a> ()</td></tr>
|
|
<tr class="memdesc:a62a9bf81fd7f15fedb29fd1348483236"><td class="mdescLeft"> </td><td class="mdescRight">Default constructor. <a href="#a62a9bf81fd7f15fedb29fd1348483236">More...</a><br /></td></tr>
|
|
<tr class="separator:a62a9bf81fd7f15fedb29fd1348483236"><td class="memSeparator" colspan="2"> </td></tr>
|
|
<tr class="memitem:a98e45f0f49af1fd99216b9195e86d86b"><td class="memItemLeft" align="right" valign="top">unsigned short </td><td class="memItemRight" valign="bottom"><a class="el" href="classsf_1_1TcpSocket.html#a98e45f0f49af1fd99216b9195e86d86b">getLocalPort</a> () const</td></tr>
|
|
<tr class="memdesc:a98e45f0f49af1fd99216b9195e86d86b"><td class="mdescLeft"> </td><td class="mdescRight">Get the port to which the socket is bound locally. <a href="#a98e45f0f49af1fd99216b9195e86d86b">More...</a><br /></td></tr>
|
|
<tr class="separator:a98e45f0f49af1fd99216b9195e86d86b"><td class="memSeparator" colspan="2"> </td></tr>
|
|
<tr class="memitem:aa8579c203b1fd21beb74d7f76444a94c"><td class="memItemLeft" align="right" valign="top"><a class="el" href="classsf_1_1IpAddress.html">IpAddress</a> </td><td class="memItemRight" valign="bottom"><a class="el" href="classsf_1_1TcpSocket.html#aa8579c203b1fd21beb74d7f76444a94c">getRemoteAddress</a> () const</td></tr>
|
|
<tr class="memdesc:aa8579c203b1fd21beb74d7f76444a94c"><td class="mdescLeft"> </td><td class="mdescRight">Get the address of the connected peer. <a href="#aa8579c203b1fd21beb74d7f76444a94c">More...</a><br /></td></tr>
|
|
<tr class="separator:aa8579c203b1fd21beb74d7f76444a94c"><td class="memSeparator" colspan="2"> </td></tr>
|
|
<tr class="memitem:a93bced0afd4b1c60797a85725be04951"><td class="memItemLeft" align="right" valign="top">unsigned short </td><td class="memItemRight" valign="bottom"><a class="el" href="classsf_1_1TcpSocket.html#a93bced0afd4b1c60797a85725be04951">getRemotePort</a> () const</td></tr>
|
|
<tr class="memdesc:a93bced0afd4b1c60797a85725be04951"><td class="mdescLeft"> </td><td class="mdescRight">Get the port of the connected peer to which the socket is connected. <a href="#a93bced0afd4b1c60797a85725be04951">More...</a><br /></td></tr>
|
|
<tr class="separator:a93bced0afd4b1c60797a85725be04951"><td class="memSeparator" colspan="2"> </td></tr>
|
|
<tr class="memitem:a68cd42d5ab70ab54b16787f555951c40"><td class="memItemLeft" align="right" valign="top"><a class="el" href="classsf_1_1Socket.html#a51bf0fd51057b98a10fbb866246176dc">Status</a> </td><td class="memItemRight" valign="bottom"><a class="el" href="classsf_1_1TcpSocket.html#a68cd42d5ab70ab54b16787f555951c40">connect</a> (const <a class="el" href="classsf_1_1IpAddress.html">IpAddress</a> &remoteAddress, unsigned short remotePort, <a class="el" href="classsf_1_1Time.html">Time</a> timeout=<a class="el" href="classsf_1_1Time.html#a8db127b632fa8da21550e7282af11fa0">Time::Zero</a>)</td></tr>
|
|
<tr class="memdesc:a68cd42d5ab70ab54b16787f555951c40"><td class="mdescLeft"> </td><td class="mdescRight">Connect the socket to a remote peer. <a href="#a68cd42d5ab70ab54b16787f555951c40">More...</a><br /></td></tr>
|
|
<tr class="separator:a68cd42d5ab70ab54b16787f555951c40"><td class="memSeparator" colspan="2"> </td></tr>
|
|
<tr class="memitem:ac18f518a9be3d6be5e74b9404c253c1e"><td class="memItemLeft" align="right" valign="top">void </td><td class="memItemRight" valign="bottom"><a class="el" href="classsf_1_1TcpSocket.html#ac18f518a9be3d6be5e74b9404c253c1e">disconnect</a> ()</td></tr>
|
|
<tr class="memdesc:ac18f518a9be3d6be5e74b9404c253c1e"><td class="mdescLeft"> </td><td class="mdescRight">Disconnect the socket from its remote peer. <a href="#ac18f518a9be3d6be5e74b9404c253c1e">More...</a><br /></td></tr>
|
|
<tr class="separator:ac18f518a9be3d6be5e74b9404c253c1e"><td class="memSeparator" colspan="2"> </td></tr>
|
|
<tr class="memitem:affce26ab3bcc4f5b9269dad79db544c0"><td class="memItemLeft" align="right" valign="top"><a class="el" href="classsf_1_1Socket.html#a51bf0fd51057b98a10fbb866246176dc">Status</a> </td><td class="memItemRight" valign="bottom"><a class="el" href="classsf_1_1TcpSocket.html#affce26ab3bcc4f5b9269dad79db544c0">send</a> (const void *data, std::size_t size)</td></tr>
|
|
<tr class="memdesc:affce26ab3bcc4f5b9269dad79db544c0"><td class="mdescLeft"> </td><td class="mdescRight">Send raw data to the remote peer. <a href="#affce26ab3bcc4f5b9269dad79db544c0">More...</a><br /></td></tr>
|
|
<tr class="separator:affce26ab3bcc4f5b9269dad79db544c0"><td class="memSeparator" colspan="2"> </td></tr>
|
|
<tr class="memitem:a31f5b280126a96c6f3ad430f4cbcb54d"><td class="memItemLeft" align="right" valign="top"><a class="el" href="classsf_1_1Socket.html#a51bf0fd51057b98a10fbb866246176dc">Status</a> </td><td class="memItemRight" valign="bottom"><a class="el" href="classsf_1_1TcpSocket.html#a31f5b280126a96c6f3ad430f4cbcb54d">send</a> (const void *data, std::size_t size, std::size_t &sent)</td></tr>
|
|
<tr class="memdesc:a31f5b280126a96c6f3ad430f4cbcb54d"><td class="mdescLeft"> </td><td class="mdescRight">Send raw data to the remote peer. <a href="#a31f5b280126a96c6f3ad430f4cbcb54d">More...</a><br /></td></tr>
|
|
<tr class="separator:a31f5b280126a96c6f3ad430f4cbcb54d"><td class="memSeparator" colspan="2"> </td></tr>
|
|
<tr class="memitem:a90ce50811ea61d4f00efc62bb99ae1af"><td class="memItemLeft" align="right" valign="top"><a class="el" href="classsf_1_1Socket.html#a51bf0fd51057b98a10fbb866246176dc">Status</a> </td><td class="memItemRight" valign="bottom"><a class="el" href="classsf_1_1TcpSocket.html#a90ce50811ea61d4f00efc62bb99ae1af">receive</a> (void *data, std::size_t size, std::size_t &received)</td></tr>
|
|
<tr class="memdesc:a90ce50811ea61d4f00efc62bb99ae1af"><td class="mdescLeft"> </td><td class="mdescRight">Receive raw data from the remote peer. <a href="#a90ce50811ea61d4f00efc62bb99ae1af">More...</a><br /></td></tr>
|
|
<tr class="separator:a90ce50811ea61d4f00efc62bb99ae1af"><td class="memSeparator" colspan="2"> </td></tr>
|
|
<tr class="memitem:a0f8276e2b1c75aac4a7b0a707b250f44"><td class="memItemLeft" align="right" valign="top"><a class="el" href="classsf_1_1Socket.html#a51bf0fd51057b98a10fbb866246176dc">Status</a> </td><td class="memItemRight" valign="bottom"><a class="el" href="classsf_1_1TcpSocket.html#a0f8276e2b1c75aac4a7b0a707b250f44">send</a> (<a class="el" href="classsf_1_1Packet.html">Packet</a> &packet)</td></tr>
|
|
<tr class="memdesc:a0f8276e2b1c75aac4a7b0a707b250f44"><td class="mdescLeft"> </td><td class="mdescRight">Send a formatted packet of data to the remote peer. <a href="#a0f8276e2b1c75aac4a7b0a707b250f44">More...</a><br /></td></tr>
|
|
<tr class="separator:a0f8276e2b1c75aac4a7b0a707b250f44"><td class="memSeparator" colspan="2"> </td></tr>
|
|
<tr class="memitem:aa655352609bc9804f2baa020df3e7331"><td class="memItemLeft" align="right" valign="top"><a class="el" href="classsf_1_1Socket.html#a51bf0fd51057b98a10fbb866246176dc">Status</a> </td><td class="memItemRight" valign="bottom"><a class="el" href="classsf_1_1TcpSocket.html#aa655352609bc9804f2baa020df3e7331">receive</a> (<a class="el" href="classsf_1_1Packet.html">Packet</a> &packet)</td></tr>
|
|
<tr class="memdesc:aa655352609bc9804f2baa020df3e7331"><td class="mdescLeft"> </td><td class="mdescRight">Receive a formatted packet of data from the remote peer. <a href="#aa655352609bc9804f2baa020df3e7331">More...</a><br /></td></tr>
|
|
<tr class="separator:aa655352609bc9804f2baa020df3e7331"><td class="memSeparator" colspan="2"> </td></tr>
|
|
<tr class="memitem:a165fc1423e281ea2714c70303d3a9782"><td class="memItemLeft" align="right" valign="top">void </td><td class="memItemRight" valign="bottom"><a class="el" href="classsf_1_1Socket.html#a165fc1423e281ea2714c70303d3a9782">setBlocking</a> (bool blocking)</td></tr>
|
|
<tr class="memdesc:a165fc1423e281ea2714c70303d3a9782"><td class="mdescLeft"> </td><td class="mdescRight">Set the blocking state of the socket. <a href="#a165fc1423e281ea2714c70303d3a9782">More...</a><br /></td></tr>
|
|
<tr class="separator:a165fc1423e281ea2714c70303d3a9782"><td class="memSeparator" colspan="2"> </td></tr>
|
|
<tr class="memitem:ab1ceca9ac114b8baeeda3b34a0aca468"><td class="memItemLeft" align="right" valign="top">bool </td><td class="memItemRight" valign="bottom"><a class="el" href="classsf_1_1Socket.html#ab1ceca9ac114b8baeeda3b34a0aca468">isBlocking</a> () const</td></tr>
|
|
<tr class="memdesc:ab1ceca9ac114b8baeeda3b34a0aca468"><td class="mdescLeft"> </td><td class="mdescRight">Tell whether the socket is in blocking or non-blocking mode. <a href="#ab1ceca9ac114b8baeeda3b34a0aca468">More...</a><br /></td></tr>
|
|
<tr class="separator:ab1ceca9ac114b8baeeda3b34a0aca468"><td class="memSeparator" colspan="2"> </td></tr>
|
|
</table><table class="memberdecls">
|
|
<tr class="heading"><td colspan="2"><h2 class="groupheader"><a name="pro-types"></a>
|
|
Protected Types</h2></td></tr>
|
|
<tr class="memitem:a5d3ff44e56e68f02816bb0fabc34adf8"><td class="memItemLeft" align="right" valign="top">enum  </td><td class="memItemRight" valign="bottom"><a class="el" href="classsf_1_1Socket.html#a5d3ff44e56e68f02816bb0fabc34adf8">Type</a> { <a class="el" href="classsf_1_1Socket.html#a5d3ff44e56e68f02816bb0fabc34adf8acc02e97e90234b957eaad4dff7f22214">Tcp</a>,
|
|
<a class="el" href="classsf_1_1Socket.html#a5d3ff44e56e68f02816bb0fabc34adf8a6ebf3094830db4820191a327f3cc6ce2">Udp</a>
|
|
}</td></tr>
|
|
<tr class="memdesc:a5d3ff44e56e68f02816bb0fabc34adf8"><td class="mdescLeft"> </td><td class="mdescRight">Types of protocols that the socket can use. <a href="classsf_1_1Socket.html#a5d3ff44e56e68f02816bb0fabc34adf8">More...</a><br /></td></tr>
|
|
<tr class="separator:a5d3ff44e56e68f02816bb0fabc34adf8"><td class="memSeparator" colspan="2"> </td></tr>
|
|
</table><table class="memberdecls">
|
|
<tr class="heading"><td colspan="2"><h2 class="groupheader"><a name="pro-methods"></a>
|
|
Protected Member Functions</h2></td></tr>
|
|
<tr class="memitem:a675457784284ae2f5640bbbe16729393"><td class="memItemLeft" align="right" valign="top">SocketHandle </td><td class="memItemRight" valign="bottom"><a class="el" href="classsf_1_1Socket.html#a675457784284ae2f5640bbbe16729393">getHandle</a> () const</td></tr>
|
|
<tr class="memdesc:a675457784284ae2f5640bbbe16729393"><td class="mdescLeft"> </td><td class="mdescRight">Return the internal handle of the socket. <a href="#a675457784284ae2f5640bbbe16729393">More...</a><br /></td></tr>
|
|
<tr class="separator:a675457784284ae2f5640bbbe16729393"><td class="memSeparator" colspan="2"> </td></tr>
|
|
<tr class="memitem:aafbe140f4b1921e0d19e88cf7a61dcbc"><td class="memItemLeft" align="right" valign="top">void </td><td class="memItemRight" valign="bottom"><a class="el" href="classsf_1_1Socket.html#aafbe140f4b1921e0d19e88cf7a61dcbc">create</a> ()</td></tr>
|
|
<tr class="memdesc:aafbe140f4b1921e0d19e88cf7a61dcbc"><td class="mdescLeft"> </td><td class="mdescRight">Create the internal representation of the socket. <a href="#aafbe140f4b1921e0d19e88cf7a61dcbc">More...</a><br /></td></tr>
|
|
<tr class="separator:aafbe140f4b1921e0d19e88cf7a61dcbc"><td class="memSeparator" colspan="2"> </td></tr>
|
|
<tr class="memitem:af1dd898f7aa3ead7ff7b2d1c20e97781"><td class="memItemLeft" align="right" valign="top">void </td><td class="memItemRight" valign="bottom"><a class="el" href="classsf_1_1Socket.html#af1dd898f7aa3ead7ff7b2d1c20e97781">create</a> (SocketHandle handle)</td></tr>
|
|
<tr class="memdesc:af1dd898f7aa3ead7ff7b2d1c20e97781"><td class="mdescLeft"> </td><td class="mdescRight">Create the internal representation of the socket from a socket handle. <a href="#af1dd898f7aa3ead7ff7b2d1c20e97781">More...</a><br /></td></tr>
|
|
<tr class="separator:af1dd898f7aa3ead7ff7b2d1c20e97781"><td class="memSeparator" colspan="2"> </td></tr>
|
|
<tr class="memitem:a71f2f5c2aa99e01cafe824fee4c573be"><td class="memItemLeft" align="right" valign="top">void </td><td class="memItemRight" valign="bottom"><a class="el" href="classsf_1_1Socket.html#a71f2f5c2aa99e01cafe824fee4c573be">close</a> ()</td></tr>
|
|
<tr class="memdesc:a71f2f5c2aa99e01cafe824fee4c573be"><td class="mdescLeft"> </td><td class="mdescRight">Close the socket gracefully. <a href="#a71f2f5c2aa99e01cafe824fee4c573be">More...</a><br /></td></tr>
|
|
<tr class="separator:a71f2f5c2aa99e01cafe824fee4c573be"><td class="memSeparator" colspan="2"> </td></tr>
|
|
</table><table class="memberdecls">
|
|
<tr class="heading"><td colspan="2"><h2 class="groupheader"><a name="friends"></a>
|
|
Friends</h2></td></tr>
|
|
<tr class="memitem:a2b2dd140834917bd44b512236bddea7c"><td class="memItemLeft" align="right" valign="top"><a id="a2b2dd140834917bd44b512236bddea7c"></a>
|
|
class </td><td class="memItemRight" valign="bottom"><b>TcpListener</b></td></tr>
|
|
<tr class="separator:a2b2dd140834917bd44b512236bddea7c"><td class="memSeparator" colspan="2"> </td></tr>
|
|
</table>
|
|
<a name="details" id="details"></a><h2 class="groupheader">Detailed Description</h2>
|
|
<div class="textblock"><p>Specialized socket using the TCP protocol. </p>
|
|
<p>TCP is a connected protocol, which means that a TCP socket can only communicate with the host it is connected to.</p>
|
|
<p>It can't send or receive anything if it is not connected.</p>
|
|
<p>The TCP protocol is reliable but adds a slight overhead. It ensures that your data will always be received in order and without errors (no data corrupted, lost or duplicated).</p>
|
|
<p>When a socket is connected to a remote host, you can retrieve informations about this host with the getRemoteAddress and getRemotePort functions. You can also get the local port to which the socket is bound (which is automatically chosen when the socket is connected), with the getLocalPort function.</p>
|
|
<p>Sending and receiving data can use either the low-level or the high-level functions. The low-level functions process a raw sequence of bytes, and cannot ensure that one call to Send will exactly match one call to Receive at the other end of the socket.</p>
|
|
<p>The high-level interface uses packets (see <a class="el" href="classsf_1_1Packet.html" title="Utility class to build blocks of data to transfer over the network. ">sf::Packet</a>), which are easier to use and provide more safety regarding the data that is exchanged. You can look at the <a class="el" href="classsf_1_1Packet.html" title="Utility class to build blocks of data to transfer over the network. ">sf::Packet</a> class to get more details about how they work.</p>
|
|
<p>The socket is automatically disconnected when it is destroyed, but if you want to explicitly close the connection while the socket instance is still alive, you can call disconnect.</p>
|
|
<p>Usage example: </p><div class="fragment"><div class="line"><span class="comment">// ----- The client -----</span></div><div class="line"></div><div class="line"><span class="comment">// Create a socket and connect it to 192.168.1.50 on port 55001</span></div><div class="line"><a class="code" href="classsf_1_1TcpSocket.html">sf::TcpSocket</a> socket;</div><div class="line">socket.<a class="code" href="classsf_1_1TcpSocket.html#a68cd42d5ab70ab54b16787f555951c40">connect</a>(<span class="stringliteral">"192.168.1.50"</span>, 55001);</div><div class="line"></div><div class="line"><span class="comment">// Send a message to the connected host</span></div><div class="line">std::string message = <span class="stringliteral">"Hi, I am a client"</span>;</div><div class="line">socket.<a class="code" href="classsf_1_1TcpSocket.html#affce26ab3bcc4f5b9269dad79db544c0">send</a>(message.c_str(), message.size() + 1);</div><div class="line"></div><div class="line"><span class="comment">// Receive an answer from the server</span></div><div class="line"><span class="keywordtype">char</span> buffer[1024];</div><div class="line">std::size_t received = 0;</div><div class="line">socket.<a class="code" href="classsf_1_1TcpSocket.html#a90ce50811ea61d4f00efc62bb99ae1af">receive</a>(buffer, <span class="keyword">sizeof</span>(buffer), received);</div><div class="line">std::cout << <span class="stringliteral">"The server said: "</span> << buffer << std::endl;</div><div class="line"></div><div class="line"><span class="comment">// ----- The server -----</span></div><div class="line"></div><div class="line"><span class="comment">// Create a listener to wait for incoming connections on port 55001</span></div><div class="line"><a class="code" href="classsf_1_1TcpListener.html">sf::TcpListener</a> listener;</div><div class="line">listener.<a class="code" href="classsf_1_1TcpListener.html#a9504758ea3570e62cb20b209c11776a1">listen</a>(55001);</div><div class="line"></div><div class="line"><span class="comment">// Wait for a connection</span></div><div class="line"><a class="code" href="classsf_1_1TcpSocket.html">sf::TcpSocket</a> socket;</div><div class="line">listener.<a class="code" href="classsf_1_1TcpListener.html#ae2c83ce5a64d50b68180c46bef0a7346">accept</a>(socket);</div><div class="line">std::cout << <span class="stringliteral">"New client connected: "</span> << socket.<a class="code" href="classsf_1_1TcpSocket.html#aa8579c203b1fd21beb74d7f76444a94c">getRemoteAddress</a>() << std::endl;</div><div class="line"></div><div class="line"><span class="comment">// Receive a message from the client</span></div><div class="line"><span class="keywordtype">char</span> buffer[1024];</div><div class="line">std::size_t received = 0;</div><div class="line">socket.<a class="code" href="classsf_1_1TcpSocket.html#a90ce50811ea61d4f00efc62bb99ae1af">receive</a>(buffer, <span class="keyword">sizeof</span>(buffer), received);</div><div class="line">std::cout << <span class="stringliteral">"The client said: "</span> << buffer << std::endl;</div><div class="line"></div><div class="line"><span class="comment">// Send an answer</span></div><div class="line">std::string message = <span class="stringliteral">"Welcome, client"</span>;</div><div class="line">socket.<a class="code" href="classsf_1_1TcpSocket.html#affce26ab3bcc4f5b9269dad79db544c0">send</a>(message.c_str(), message.size() + 1);</div></div><!-- fragment --><dl class="section see"><dt>See also</dt><dd><a class="el" href="classsf_1_1Socket.html" title="Base class for all the socket types. ">sf::Socket</a>, <a class="el" href="classsf_1_1UdpSocket.html" title="Specialized socket using the UDP protocol. ">sf::UdpSocket</a>, <a class="el" href="classsf_1_1Packet.html" title="Utility class to build blocks of data to transfer over the network. ">sf::Packet</a> </dd></dl>
|
|
|
|
<p class="definition">Definition at line <a class="el" href="TcpSocket_8hpp_source.html#l00046">46</a> of file <a class="el" href="TcpSocket_8hpp_source.html">TcpSocket.hpp</a>.</p>
|
|
</div><h2 class="groupheader">Member Enumeration Documentation</h2>
|
|
<a id="aa3e6c984bcb81a35234dcc9cc8369d75"></a>
|
|
<h2 class="memtitle"><span class="permalink"><a href="#aa3e6c984bcb81a35234dcc9cc8369d75">◆ </a></span>anonymous enum</h2>
|
|
|
|
<div class="memitem">
|
|
<div class="memproto">
|
|
<table class="mlabels">
|
|
<tr>
|
|
<td class="mlabels-left">
|
|
<table class="memname">
|
|
<tr>
|
|
<td class="memname">anonymous enum</td>
|
|
</tr>
|
|
</table>
|
|
</td>
|
|
<td class="mlabels-right">
|
|
<span class="mlabels"><span class="mlabel">inherited</span></span> </td>
|
|
</tr>
|
|
</table>
|
|
</div><div class="memdoc">
|
|
|
|
<p>Some special values used by sockets. </p>
|
|
<table class="fieldtable">
|
|
<tr><th colspan="2">Enumerator</th></tr><tr><td class="fieldname"><a id="aa3e6c984bcb81a35234dcc9cc8369d75a5a3c30fd128895403afc11076f461b19"></a>AnyPort </td><td class="fielddoc"><p>Special value that tells the system to pick any available port. </p>
|
|
</td></tr>
|
|
</table>
|
|
|
|
<p class="definition">Definition at line <a class="el" href="Socket_8hpp_source.html#l00066">66</a> of file <a class="el" href="Socket_8hpp_source.html">Socket.hpp</a>.</p>
|
|
|
|
</div>
|
|
</div>
|
|
<a id="a51bf0fd51057b98a10fbb866246176dc"></a>
|
|
<h2 class="memtitle"><span class="permalink"><a href="#a51bf0fd51057b98a10fbb866246176dc">◆ </a></span>Status</h2>
|
|
|
|
<div class="memitem">
|
|
<div class="memproto">
|
|
<table class="mlabels">
|
|
<tr>
|
|
<td class="mlabels-left">
|
|
<table class="memname">
|
|
<tr>
|
|
<td class="memname">enum <a class="el" href="classsf_1_1Socket.html#a51bf0fd51057b98a10fbb866246176dc">sf::Socket::Status</a></td>
|
|
</tr>
|
|
</table>
|
|
</td>
|
|
<td class="mlabels-right">
|
|
<span class="mlabels"><span class="mlabel">inherited</span></span> </td>
|
|
</tr>
|
|
</table>
|
|
</div><div class="memdoc">
|
|
|
|
<p>Status codes that may be returned by socket functions. </p>
|
|
<table class="fieldtable">
|
|
<tr><th colspan="2">Enumerator</th></tr><tr><td class="fieldname"><a id="a51bf0fd51057b98a10fbb866246176dca1de3a85bc56d3ae85b3d0f3cfd04ae90"></a>Done </td><td class="fielddoc"><p>The socket has sent / received the data. </p>
|
|
</td></tr>
|
|
<tr><td class="fieldname"><a id="a51bf0fd51057b98a10fbb866246176dca8554848daae98f996e131bdeed076c09"></a>NotReady </td><td class="fielddoc"><p>The socket is not ready to send / receive data yet. </p>
|
|
</td></tr>
|
|
<tr><td class="fieldname"><a id="a51bf0fd51057b98a10fbb866246176dca181c163fad2eaea927185d127c392706"></a>Partial </td><td class="fielddoc"><p>The socket sent a part of the data. </p>
|
|
</td></tr>
|
|
<tr><td class="fieldname"><a id="a51bf0fd51057b98a10fbb866246176dcab215141f756acdc23c67fad149710eb1"></a>Disconnected </td><td class="fielddoc"><p>The TCP socket has been disconnected. </p>
|
|
</td></tr>
|
|
<tr><td class="fieldname"><a id="a51bf0fd51057b98a10fbb866246176dca1dc9854433a28c22e192721179a2df5d"></a>Error </td><td class="fielddoc"><p>An unexpected error happened. </p>
|
|
</td></tr>
|
|
</table>
|
|
|
|
<p class="definition">Definition at line <a class="el" href="Socket_8hpp_source.html#l00053">53</a> of file <a class="el" href="Socket_8hpp_source.html">Socket.hpp</a>.</p>
|
|
|
|
</div>
|
|
</div>
|
|
<a id="a5d3ff44e56e68f02816bb0fabc34adf8"></a>
|
|
<h2 class="memtitle"><span class="permalink"><a href="#a5d3ff44e56e68f02816bb0fabc34adf8">◆ </a></span>Type</h2>
|
|
|
|
<div class="memitem">
|
|
<div class="memproto">
|
|
<table class="mlabels">
|
|
<tr>
|
|
<td class="mlabels-left">
|
|
<table class="memname">
|
|
<tr>
|
|
<td class="memname">enum <a class="el" href="classsf_1_1Socket.html#a5d3ff44e56e68f02816bb0fabc34adf8">sf::Socket::Type</a></td>
|
|
</tr>
|
|
</table>
|
|
</td>
|
|
<td class="mlabels-right">
|
|
<span class="mlabels"><span class="mlabel">protected</span><span class="mlabel">inherited</span></span> </td>
|
|
</tr>
|
|
</table>
|
|
</div><div class="memdoc">
|
|
|
|
<p>Types of protocols that the socket can use. </p>
|
|
<table class="fieldtable">
|
|
<tr><th colspan="2">Enumerator</th></tr><tr><td class="fieldname"><a id="a5d3ff44e56e68f02816bb0fabc34adf8acc02e97e90234b957eaad4dff7f22214"></a>Tcp </td><td class="fielddoc"><p>TCP protocol. </p>
|
|
</td></tr>
|
|
<tr><td class="fieldname"><a id="a5d3ff44e56e68f02816bb0fabc34adf8a6ebf3094830db4820191a327f3cc6ce2"></a>Udp </td><td class="fielddoc"><p>UDP protocol. </p>
|
|
</td></tr>
|
|
</table>
|
|
|
|
<p class="definition">Definition at line <a class="el" href="Socket_8hpp_source.html#l00114">114</a> of file <a class="el" href="Socket_8hpp_source.html">Socket.hpp</a>.</p>
|
|
|
|
</div>
|
|
</div>
|
|
<h2 class="groupheader">Constructor & Destructor Documentation</h2>
|
|
<a id="a62a9bf81fd7f15fedb29fd1348483236"></a>
|
|
<h2 class="memtitle"><span class="permalink"><a href="#a62a9bf81fd7f15fedb29fd1348483236">◆ </a></span>TcpSocket()</h2>
|
|
|
|
<div class="memitem">
|
|
<div class="memproto">
|
|
<table class="memname">
|
|
<tr>
|
|
<td class="memname">sf::TcpSocket::TcpSocket </td>
|
|
<td>(</td>
|
|
<td class="paramname"></td><td>)</td>
|
|
<td></td>
|
|
</tr>
|
|
</table>
|
|
</div><div class="memdoc">
|
|
|
|
<p>Default constructor. </p>
|
|
|
|
</div>
|
|
</div>
|
|
<h2 class="groupheader">Member Function Documentation</h2>
|
|
<a id="a71f2f5c2aa99e01cafe824fee4c573be"></a>
|
|
<h2 class="memtitle"><span class="permalink"><a href="#a71f2f5c2aa99e01cafe824fee4c573be">◆ </a></span>close()</h2>
|
|
|
|
<div class="memitem">
|
|
<div class="memproto">
|
|
<table class="mlabels">
|
|
<tr>
|
|
<td class="mlabels-left">
|
|
<table class="memname">
|
|
<tr>
|
|
<td class="memname">void sf::Socket::close </td>
|
|
<td>(</td>
|
|
<td class="paramname"></td><td>)</td>
|
|
<td></td>
|
|
</tr>
|
|
</table>
|
|
</td>
|
|
<td class="mlabels-right">
|
|
<span class="mlabels"><span class="mlabel">protected</span><span class="mlabel">inherited</span></span> </td>
|
|
</tr>
|
|
</table>
|
|
</div><div class="memdoc">
|
|
|
|
<p>Close the socket gracefully. </p>
|
|
<p>This function can only be accessed by derived classes. </p>
|
|
|
|
</div>
|
|
</div>
|
|
<a id="a68cd42d5ab70ab54b16787f555951c40"></a>
|
|
<h2 class="memtitle"><span class="permalink"><a href="#a68cd42d5ab70ab54b16787f555951c40">◆ </a></span>connect()</h2>
|
|
|
|
<div class="memitem">
|
|
<div class="memproto">
|
|
<table class="memname">
|
|
<tr>
|
|
<td class="memname"><a class="el" href="classsf_1_1Socket.html#a51bf0fd51057b98a10fbb866246176dc">Status</a> sf::TcpSocket::connect </td>
|
|
<td>(</td>
|
|
<td class="paramtype">const <a class="el" href="classsf_1_1IpAddress.html">IpAddress</a> & </td>
|
|
<td class="paramname"><em>remoteAddress</em>, </td>
|
|
</tr>
|
|
<tr>
|
|
<td class="paramkey"></td>
|
|
<td></td>
|
|
<td class="paramtype">unsigned short </td>
|
|
<td class="paramname"><em>remotePort</em>, </td>
|
|
</tr>
|
|
<tr>
|
|
<td class="paramkey"></td>
|
|
<td></td>
|
|
<td class="paramtype"><a class="el" href="classsf_1_1Time.html">Time</a> </td>
|
|
<td class="paramname"><em>timeout</em> = <code><a class="el" href="classsf_1_1Time.html#a8db127b632fa8da21550e7282af11fa0">Time::Zero</a></code> </td>
|
|
</tr>
|
|
<tr>
|
|
<td></td>
|
|
<td>)</td>
|
|
<td></td><td></td>
|
|
</tr>
|
|
</table>
|
|
</div><div class="memdoc">
|
|
|
|
<p>Connect the socket to a remote peer. </p>
|
|
<p>In blocking mode, this function may take a while, especially if the remote peer is not reachable. The last parameter allows you to stop trying to connect after a given timeout. If the socket is already connected, the connection is forcibly disconnected before attempting to connect again.</p>
|
|
<dl class="params"><dt>Parameters</dt><dd>
|
|
<table class="params">
|
|
<tr><td class="paramname">remoteAddress</td><td>Address of the remote peer </td></tr>
|
|
<tr><td class="paramname">remotePort</td><td>Port of the remote peer </td></tr>
|
|
<tr><td class="paramname">timeout</td><td>Optional maximum time to wait</td></tr>
|
|
</table>
|
|
</dd>
|
|
</dl>
|
|
<dl class="section return"><dt>Returns</dt><dd>Status code</dd></dl>
|
|
<dl class="section see"><dt>See also</dt><dd><a class="el" href="classsf_1_1TcpSocket.html#ac18f518a9be3d6be5e74b9404c253c1e" title="Disconnect the socket from its remote peer. ">disconnect</a> </dd></dl>
|
|
|
|
</div>
|
|
</div>
|
|
<a id="aafbe140f4b1921e0d19e88cf7a61dcbc"></a>
|
|
<h2 class="memtitle"><span class="permalink"><a href="#aafbe140f4b1921e0d19e88cf7a61dcbc">◆ </a></span>create() <span class="overload">[1/2]</span></h2>
|
|
|
|
<div class="memitem">
|
|
<div class="memproto">
|
|
<table class="mlabels">
|
|
<tr>
|
|
<td class="mlabels-left">
|
|
<table class="memname">
|
|
<tr>
|
|
<td class="memname">void sf::Socket::create </td>
|
|
<td>(</td>
|
|
<td class="paramname"></td><td>)</td>
|
|
<td></td>
|
|
</tr>
|
|
</table>
|
|
</td>
|
|
<td class="mlabels-right">
|
|
<span class="mlabels"><span class="mlabel">protected</span><span class="mlabel">inherited</span></span> </td>
|
|
</tr>
|
|
</table>
|
|
</div><div class="memdoc">
|
|
|
|
<p>Create the internal representation of the socket. </p>
|
|
<p>This function can only be accessed by derived classes. </p>
|
|
|
|
</div>
|
|
</div>
|
|
<a id="af1dd898f7aa3ead7ff7b2d1c20e97781"></a>
|
|
<h2 class="memtitle"><span class="permalink"><a href="#af1dd898f7aa3ead7ff7b2d1c20e97781">◆ </a></span>create() <span class="overload">[2/2]</span></h2>
|
|
|
|
<div class="memitem">
|
|
<div class="memproto">
|
|
<table class="mlabels">
|
|
<tr>
|
|
<td class="mlabels-left">
|
|
<table class="memname">
|
|
<tr>
|
|
<td class="memname">void sf::Socket::create </td>
|
|
<td>(</td>
|
|
<td class="paramtype">SocketHandle </td>
|
|
<td class="paramname"><em>handle</em></td><td>)</td>
|
|
<td></td>
|
|
</tr>
|
|
</table>
|
|
</td>
|
|
<td class="mlabels-right">
|
|
<span class="mlabels"><span class="mlabel">protected</span><span class="mlabel">inherited</span></span> </td>
|
|
</tr>
|
|
</table>
|
|
</div><div class="memdoc">
|
|
|
|
<p>Create the internal representation of the socket from a socket handle. </p>
|
|
<p>This function can only be accessed by derived classes.</p>
|
|
<dl class="params"><dt>Parameters</dt><dd>
|
|
<table class="params">
|
|
<tr><td class="paramname">handle</td><td>OS-specific handle of the socket to wrap </td></tr>
|
|
</table>
|
|
</dd>
|
|
</dl>
|
|
|
|
</div>
|
|
</div>
|
|
<a id="ac18f518a9be3d6be5e74b9404c253c1e"></a>
|
|
<h2 class="memtitle"><span class="permalink"><a href="#ac18f518a9be3d6be5e74b9404c253c1e">◆ </a></span>disconnect()</h2>
|
|
|
|
<div class="memitem">
|
|
<div class="memproto">
|
|
<table class="memname">
|
|
<tr>
|
|
<td class="memname">void sf::TcpSocket::disconnect </td>
|
|
<td>(</td>
|
|
<td class="paramname"></td><td>)</td>
|
|
<td></td>
|
|
</tr>
|
|
</table>
|
|
</div><div class="memdoc">
|
|
|
|
<p>Disconnect the socket from its remote peer. </p>
|
|
<p>This function gracefully closes the connection. If the socket is not connected, this function has no effect.</p>
|
|
<dl class="section see"><dt>See also</dt><dd><a class="el" href="classsf_1_1TcpSocket.html#a68cd42d5ab70ab54b16787f555951c40" title="Connect the socket to a remote peer. ">connect</a> </dd></dl>
|
|
|
|
</div>
|
|
</div>
|
|
<a id="a675457784284ae2f5640bbbe16729393"></a>
|
|
<h2 class="memtitle"><span class="permalink"><a href="#a675457784284ae2f5640bbbe16729393">◆ </a></span>getHandle()</h2>
|
|
|
|
<div class="memitem">
|
|
<div class="memproto">
|
|
<table class="mlabels">
|
|
<tr>
|
|
<td class="mlabels-left">
|
|
<table class="memname">
|
|
<tr>
|
|
<td class="memname">SocketHandle sf::Socket::getHandle </td>
|
|
<td>(</td>
|
|
<td class="paramname"></td><td>)</td>
|
|
<td> const</td>
|
|
</tr>
|
|
</table>
|
|
</td>
|
|
<td class="mlabels-right">
|
|
<span class="mlabels"><span class="mlabel">protected</span><span class="mlabel">inherited</span></span> </td>
|
|
</tr>
|
|
</table>
|
|
</div><div class="memdoc">
|
|
|
|
<p>Return the internal handle of the socket. </p>
|
|
<p>The returned handle may be invalid if the socket was not created yet (or already destroyed). This function can only be accessed by derived classes.</p>
|
|
<dl class="section return"><dt>Returns</dt><dd>The internal (OS-specific) handle of the socket </dd></dl>
|
|
|
|
</div>
|
|
</div>
|
|
<a id="a98e45f0f49af1fd99216b9195e86d86b"></a>
|
|
<h2 class="memtitle"><span class="permalink"><a href="#a98e45f0f49af1fd99216b9195e86d86b">◆ </a></span>getLocalPort()</h2>
|
|
|
|
<div class="memitem">
|
|
<div class="memproto">
|
|
<table class="memname">
|
|
<tr>
|
|
<td class="memname">unsigned short sf::TcpSocket::getLocalPort </td>
|
|
<td>(</td>
|
|
<td class="paramname"></td><td>)</td>
|
|
<td> const</td>
|
|
</tr>
|
|
</table>
|
|
</div><div class="memdoc">
|
|
|
|
<p>Get the port to which the socket is bound locally. </p>
|
|
<p>If the socket is not connected, this function returns 0.</p>
|
|
<dl class="section return"><dt>Returns</dt><dd>Port to which the socket is bound</dd></dl>
|
|
<dl class="section see"><dt>See also</dt><dd><a class="el" href="classsf_1_1TcpSocket.html#a68cd42d5ab70ab54b16787f555951c40" title="Connect the socket to a remote peer. ">connect</a>, <a class="el" href="classsf_1_1TcpSocket.html#a93bced0afd4b1c60797a85725be04951" title="Get the port of the connected peer to which the socket is connected. ">getRemotePort</a> </dd></dl>
|
|
|
|
</div>
|
|
</div>
|
|
<a id="aa8579c203b1fd21beb74d7f76444a94c"></a>
|
|
<h2 class="memtitle"><span class="permalink"><a href="#aa8579c203b1fd21beb74d7f76444a94c">◆ </a></span>getRemoteAddress()</h2>
|
|
|
|
<div class="memitem">
|
|
<div class="memproto">
|
|
<table class="memname">
|
|
<tr>
|
|
<td class="memname"><a class="el" href="classsf_1_1IpAddress.html">IpAddress</a> sf::TcpSocket::getRemoteAddress </td>
|
|
<td>(</td>
|
|
<td class="paramname"></td><td>)</td>
|
|
<td> const</td>
|
|
</tr>
|
|
</table>
|
|
</div><div class="memdoc">
|
|
|
|
<p>Get the address of the connected peer. </p>
|
|
<p>It the socket is not connected, this function returns <a class="el" href="classsf_1_1IpAddress.html#a4619b4abbe3c8fef056e7299db967404" title="Value representing an empty/invalid address. ">sf::IpAddress::None</a>.</p>
|
|
<dl class="section return"><dt>Returns</dt><dd>Address of the remote peer</dd></dl>
|
|
<dl class="section see"><dt>See also</dt><dd><a class="el" href="classsf_1_1TcpSocket.html#a93bced0afd4b1c60797a85725be04951" title="Get the port of the connected peer to which the socket is connected. ">getRemotePort</a> </dd></dl>
|
|
|
|
</div>
|
|
</div>
|
|
<a id="a93bced0afd4b1c60797a85725be04951"></a>
|
|
<h2 class="memtitle"><span class="permalink"><a href="#a93bced0afd4b1c60797a85725be04951">◆ </a></span>getRemotePort()</h2>
|
|
|
|
<div class="memitem">
|
|
<div class="memproto">
|
|
<table class="memname">
|
|
<tr>
|
|
<td class="memname">unsigned short sf::TcpSocket::getRemotePort </td>
|
|
<td>(</td>
|
|
<td class="paramname"></td><td>)</td>
|
|
<td> const</td>
|
|
</tr>
|
|
</table>
|
|
</div><div class="memdoc">
|
|
|
|
<p>Get the port of the connected peer to which the socket is connected. </p>
|
|
<p>If the socket is not connected, this function returns 0.</p>
|
|
<dl class="section return"><dt>Returns</dt><dd>Remote port to which the socket is connected</dd></dl>
|
|
<dl class="section see"><dt>See also</dt><dd><a class="el" href="classsf_1_1TcpSocket.html#aa8579c203b1fd21beb74d7f76444a94c" title="Get the address of the connected peer. ">getRemoteAddress</a> </dd></dl>
|
|
|
|
</div>
|
|
</div>
|
|
<a id="ab1ceca9ac114b8baeeda3b34a0aca468"></a>
|
|
<h2 class="memtitle"><span class="permalink"><a href="#ab1ceca9ac114b8baeeda3b34a0aca468">◆ </a></span>isBlocking()</h2>
|
|
|
|
<div class="memitem">
|
|
<div class="memproto">
|
|
<table class="mlabels">
|
|
<tr>
|
|
<td class="mlabels-left">
|
|
<table class="memname">
|
|
<tr>
|
|
<td class="memname">bool sf::Socket::isBlocking </td>
|
|
<td>(</td>
|
|
<td class="paramname"></td><td>)</td>
|
|
<td> const</td>
|
|
</tr>
|
|
</table>
|
|
</td>
|
|
<td class="mlabels-right">
|
|
<span class="mlabels"><span class="mlabel">inherited</span></span> </td>
|
|
</tr>
|
|
</table>
|
|
</div><div class="memdoc">
|
|
|
|
<p>Tell whether the socket is in blocking or non-blocking mode. </p>
|
|
<dl class="section return"><dt>Returns</dt><dd>True if the socket is blocking, false otherwise</dd></dl>
|
|
<dl class="section see"><dt>See also</dt><dd><a class="el" href="classsf_1_1Socket.html#a165fc1423e281ea2714c70303d3a9782" title="Set the blocking state of the socket. ">setBlocking</a> </dd></dl>
|
|
|
|
</div>
|
|
</div>
|
|
<a id="a90ce50811ea61d4f00efc62bb99ae1af"></a>
|
|
<h2 class="memtitle"><span class="permalink"><a href="#a90ce50811ea61d4f00efc62bb99ae1af">◆ </a></span>receive() <span class="overload">[1/2]</span></h2>
|
|
|
|
<div class="memitem">
|
|
<div class="memproto">
|
|
<table class="memname">
|
|
<tr>
|
|
<td class="memname"><a class="el" href="classsf_1_1Socket.html#a51bf0fd51057b98a10fbb866246176dc">Status</a> sf::TcpSocket::receive </td>
|
|
<td>(</td>
|
|
<td class="paramtype">void * </td>
|
|
<td class="paramname"><em>data</em>, </td>
|
|
</tr>
|
|
<tr>
|
|
<td class="paramkey"></td>
|
|
<td></td>
|
|
<td class="paramtype">std::size_t </td>
|
|
<td class="paramname"><em>size</em>, </td>
|
|
</tr>
|
|
<tr>
|
|
<td class="paramkey"></td>
|
|
<td></td>
|
|
<td class="paramtype">std::size_t & </td>
|
|
<td class="paramname"><em>received</em> </td>
|
|
</tr>
|
|
<tr>
|
|
<td></td>
|
|
<td>)</td>
|
|
<td></td><td></td>
|
|
</tr>
|
|
</table>
|
|
</div><div class="memdoc">
|
|
|
|
<p>Receive raw data from the remote peer. </p>
|
|
<p>In blocking mode, this function will wait until some bytes are actually received. This function will fail if the socket is not connected.</p>
|
|
<dl class="params"><dt>Parameters</dt><dd>
|
|
<table class="params">
|
|
<tr><td class="paramname">data</td><td>Pointer to the array to fill with the received bytes </td></tr>
|
|
<tr><td class="paramname">size</td><td>Maximum number of bytes that can be received </td></tr>
|
|
<tr><td class="paramname">received</td><td>This variable is filled with the actual number of bytes received</td></tr>
|
|
</table>
|
|
</dd>
|
|
</dl>
|
|
<dl class="section return"><dt>Returns</dt><dd>Status code</dd></dl>
|
|
<dl class="section see"><dt>See also</dt><dd><a class="el" href="classsf_1_1TcpSocket.html#affce26ab3bcc4f5b9269dad79db544c0" title="Send raw data to the remote peer. ">send</a> </dd></dl>
|
|
|
|
</div>
|
|
</div>
|
|
<a id="aa655352609bc9804f2baa020df3e7331"></a>
|
|
<h2 class="memtitle"><span class="permalink"><a href="#aa655352609bc9804f2baa020df3e7331">◆ </a></span>receive() <span class="overload">[2/2]</span></h2>
|
|
|
|
<div class="memitem">
|
|
<div class="memproto">
|
|
<table class="memname">
|
|
<tr>
|
|
<td class="memname"><a class="el" href="classsf_1_1Socket.html#a51bf0fd51057b98a10fbb866246176dc">Status</a> sf::TcpSocket::receive </td>
|
|
<td>(</td>
|
|
<td class="paramtype"><a class="el" href="classsf_1_1Packet.html">Packet</a> & </td>
|
|
<td class="paramname"><em>packet</em></td><td>)</td>
|
|
<td></td>
|
|
</tr>
|
|
</table>
|
|
</div><div class="memdoc">
|
|
|
|
<p>Receive a formatted packet of data from the remote peer. </p>
|
|
<p>In blocking mode, this function will wait until the whole packet has been received. This function will fail if the socket is not connected.</p>
|
|
<dl class="params"><dt>Parameters</dt><dd>
|
|
<table class="params">
|
|
<tr><td class="paramname">packet</td><td><a class="el" href="classsf_1_1Packet.html" title="Utility class to build blocks of data to transfer over the network. ">Packet</a> to fill with the received data</td></tr>
|
|
</table>
|
|
</dd>
|
|
</dl>
|
|
<dl class="section return"><dt>Returns</dt><dd>Status code</dd></dl>
|
|
<dl class="section see"><dt>See also</dt><dd><a class="el" href="classsf_1_1TcpSocket.html#affce26ab3bcc4f5b9269dad79db544c0" title="Send raw data to the remote peer. ">send</a> </dd></dl>
|
|
|
|
</div>
|
|
</div>
|
|
<a id="affce26ab3bcc4f5b9269dad79db544c0"></a>
|
|
<h2 class="memtitle"><span class="permalink"><a href="#affce26ab3bcc4f5b9269dad79db544c0">◆ </a></span>send() <span class="overload">[1/3]</span></h2>
|
|
|
|
<div class="memitem">
|
|
<div class="memproto">
|
|
<table class="memname">
|
|
<tr>
|
|
<td class="memname"><a class="el" href="classsf_1_1Socket.html#a51bf0fd51057b98a10fbb866246176dc">Status</a> sf::TcpSocket::send </td>
|
|
<td>(</td>
|
|
<td class="paramtype">const void * </td>
|
|
<td class="paramname"><em>data</em>, </td>
|
|
</tr>
|
|
<tr>
|
|
<td class="paramkey"></td>
|
|
<td></td>
|
|
<td class="paramtype">std::size_t </td>
|
|
<td class="paramname"><em>size</em> </td>
|
|
</tr>
|
|
<tr>
|
|
<td></td>
|
|
<td>)</td>
|
|
<td></td><td></td>
|
|
</tr>
|
|
</table>
|
|
</div><div class="memdoc">
|
|
|
|
<p>Send raw data to the remote peer. </p>
|
|
<p>To be able to handle partial sends over non-blocking sockets, use the <a class="el" href="classsf_1_1TcpSocket.html#a31f5b280126a96c6f3ad430f4cbcb54d" title="Send raw data to the remote peer. ">send(const void*, std::size_t, std::size_t&)</a> overload instead. This function will fail if the socket is not connected.</p>
|
|
<dl class="params"><dt>Parameters</dt><dd>
|
|
<table class="params">
|
|
<tr><td class="paramname">data</td><td>Pointer to the sequence of bytes to send </td></tr>
|
|
<tr><td class="paramname">size</td><td>Number of bytes to send</td></tr>
|
|
</table>
|
|
</dd>
|
|
</dl>
|
|
<dl class="section return"><dt>Returns</dt><dd>Status code</dd></dl>
|
|
<dl class="section see"><dt>See also</dt><dd><a class="el" href="classsf_1_1TcpSocket.html#a90ce50811ea61d4f00efc62bb99ae1af" title="Receive raw data from the remote peer. ">receive</a> </dd></dl>
|
|
|
|
</div>
|
|
</div>
|
|
<a id="a31f5b280126a96c6f3ad430f4cbcb54d"></a>
|
|
<h2 class="memtitle"><span class="permalink"><a href="#a31f5b280126a96c6f3ad430f4cbcb54d">◆ </a></span>send() <span class="overload">[2/3]</span></h2>
|
|
|
|
<div class="memitem">
|
|
<div class="memproto">
|
|
<table class="memname">
|
|
<tr>
|
|
<td class="memname"><a class="el" href="classsf_1_1Socket.html#a51bf0fd51057b98a10fbb866246176dc">Status</a> sf::TcpSocket::send </td>
|
|
<td>(</td>
|
|
<td class="paramtype">const void * </td>
|
|
<td class="paramname"><em>data</em>, </td>
|
|
</tr>
|
|
<tr>
|
|
<td class="paramkey"></td>
|
|
<td></td>
|
|
<td class="paramtype">std::size_t </td>
|
|
<td class="paramname"><em>size</em>, </td>
|
|
</tr>
|
|
<tr>
|
|
<td class="paramkey"></td>
|
|
<td></td>
|
|
<td class="paramtype">std::size_t & </td>
|
|
<td class="paramname"><em>sent</em> </td>
|
|
</tr>
|
|
<tr>
|
|
<td></td>
|
|
<td>)</td>
|
|
<td></td><td></td>
|
|
</tr>
|
|
</table>
|
|
</div><div class="memdoc">
|
|
|
|
<p>Send raw data to the remote peer. </p>
|
|
<p>This function will fail if the socket is not connected.</p>
|
|
<dl class="params"><dt>Parameters</dt><dd>
|
|
<table class="params">
|
|
<tr><td class="paramname">data</td><td>Pointer to the sequence of bytes to send </td></tr>
|
|
<tr><td class="paramname">size</td><td>Number of bytes to send </td></tr>
|
|
<tr><td class="paramname">sent</td><td>The number of bytes sent will be written here</td></tr>
|
|
</table>
|
|
</dd>
|
|
</dl>
|
|
<dl class="section return"><dt>Returns</dt><dd>Status code</dd></dl>
|
|
<dl class="section see"><dt>See also</dt><dd><a class="el" href="classsf_1_1TcpSocket.html#a90ce50811ea61d4f00efc62bb99ae1af" title="Receive raw data from the remote peer. ">receive</a> </dd></dl>
|
|
|
|
</div>
|
|
</div>
|
|
<a id="a0f8276e2b1c75aac4a7b0a707b250f44"></a>
|
|
<h2 class="memtitle"><span class="permalink"><a href="#a0f8276e2b1c75aac4a7b0a707b250f44">◆ </a></span>send() <span class="overload">[3/3]</span></h2>
|
|
|
|
<div class="memitem">
|
|
<div class="memproto">
|
|
<table class="memname">
|
|
<tr>
|
|
<td class="memname"><a class="el" href="classsf_1_1Socket.html#a51bf0fd51057b98a10fbb866246176dc">Status</a> sf::TcpSocket::send </td>
|
|
<td>(</td>
|
|
<td class="paramtype"><a class="el" href="classsf_1_1Packet.html">Packet</a> & </td>
|
|
<td class="paramname"><em>packet</em></td><td>)</td>
|
|
<td></td>
|
|
</tr>
|
|
</table>
|
|
</div><div class="memdoc">
|
|
|
|
<p>Send a formatted packet of data to the remote peer. </p>
|
|
<p>In non-blocking mode, if this function returns <a class="el" href="classsf_1_1Socket.html#a51bf0fd51057b98a10fbb866246176dca181c163fad2eaea927185d127c392706" title="The socket sent a part of the data. ">sf::Socket::Partial</a>, you <em>must</em> retry sending the same unmodified packet before sending anything else in order to guarantee the packet arrives at the remote peer uncorrupted. This function will fail if the socket is not connected.</p>
|
|
<dl class="params"><dt>Parameters</dt><dd>
|
|
<table class="params">
|
|
<tr><td class="paramname">packet</td><td><a class="el" href="classsf_1_1Packet.html" title="Utility class to build blocks of data to transfer over the network. ">Packet</a> to send</td></tr>
|
|
</table>
|
|
</dd>
|
|
</dl>
|
|
<dl class="section return"><dt>Returns</dt><dd>Status code</dd></dl>
|
|
<dl class="section see"><dt>See also</dt><dd><a class="el" href="classsf_1_1TcpSocket.html#a90ce50811ea61d4f00efc62bb99ae1af" title="Receive raw data from the remote peer. ">receive</a> </dd></dl>
|
|
|
|
</div>
|
|
</div>
|
|
<a id="a165fc1423e281ea2714c70303d3a9782"></a>
|
|
<h2 class="memtitle"><span class="permalink"><a href="#a165fc1423e281ea2714c70303d3a9782">◆ </a></span>setBlocking()</h2>
|
|
|
|
<div class="memitem">
|
|
<div class="memproto">
|
|
<table class="mlabels">
|
|
<tr>
|
|
<td class="mlabels-left">
|
|
<table class="memname">
|
|
<tr>
|
|
<td class="memname">void sf::Socket::setBlocking </td>
|
|
<td>(</td>
|
|
<td class="paramtype">bool </td>
|
|
<td class="paramname"><em>blocking</em></td><td>)</td>
|
|
<td></td>
|
|
</tr>
|
|
</table>
|
|
</td>
|
|
<td class="mlabels-right">
|
|
<span class="mlabels"><span class="mlabel">inherited</span></span> </td>
|
|
</tr>
|
|
</table>
|
|
</div><div class="memdoc">
|
|
|
|
<p>Set the blocking state of the socket. </p>
|
|
<p>In blocking mode, calls will not return until they have completed their task. For example, a call to Receive in blocking mode won't return until some data was actually received. In non-blocking mode, calls will always return immediately, using the return code to signal whether there was data available or not. By default, all sockets are blocking.</p>
|
|
<dl class="params"><dt>Parameters</dt><dd>
|
|
<table class="params">
|
|
<tr><td class="paramname">blocking</td><td>True to set the socket as blocking, false for non-blocking</td></tr>
|
|
</table>
|
|
</dd>
|
|
</dl>
|
|
<dl class="section see"><dt>See also</dt><dd><a class="el" href="classsf_1_1Socket.html#ab1ceca9ac114b8baeeda3b34a0aca468" title="Tell whether the socket is in blocking or non-blocking mode. ">isBlocking</a> </dd></dl>
|
|
|
|
</div>
|
|
</div>
|
|
<hr/>The documentation for this class was generated from the following file:<ul>
|
|
<li><a class="el" href="TcpSocket_8hpp_source.html">TcpSocket.hpp</a></li>
|
|
</ul>
|
|
</div><!-- contents -->
|
|
</div>
|
|
<div id="footer-container">
|
|
<div id="footer">
|
|
SFML is licensed under the terms and conditions of the <a href="https://www.sfml-dev.org/license.php">zlib/png license</a>.<br>
|
|
Copyright © Laurent Gomila ::
|
|
Documentation generated by <a href="http://www.doxygen.org/" title="doxygen website">doxygen</a> ::
|
|
</div>
|
|
</div>
|
|
</body>
|
|
</html>
|