rsc3/doc-schelp/Help-3.12.2/Classes/NetAddr.html

161 lines
13 KiB
HTML
Raw Permalink Normal View History

2022-08-24 13:53:18 +00:00
<html><head><title>NetAddr</title>
<link rel='stylesheet' href='./../scdoc.css' type='text/css' />
<link rel='stylesheet' href='./../frontend.css' type='text/css' />
<link rel='stylesheet' href='./../custom.css' type='text/css' />
<meta http-equiv='Content-Type' content='text/html; charset=UTF-8' />
<script src='./../scdoc.js' type='text/javascript'></script>
<script src='./../docmap.js' type='text/javascript'></script>
<script src='./../prettify.js' type='text/javascript'></script>
<script src='./../lang-sc.js' type='text/javascript'></script>
<script type='text/javascript'>var helpRoot='./..';</script>
</head>
<ul id='menubar'></ul>
<body onload='fixTOC();prettyPrint()'>
<div class='contents'>
<div class='header'>
<div id='label'>SuperCollider CLASSES</div>
<div id='categories'><a href='./../Browse.html#Control'>Control</a>, <a href='./../Browse.html#External Control>OSC'>External Control>OSC</a></div>
<h1>NetAddr</h1>
<div id='summary'>network address</div>
</div>
<div class='subheader'>
<div id='filename'>Source: <a href='file:///Applications/SuperCollider.app/Contents/Resources/SCClassLibrary/Common/Control/NetAddr.sc'>/Applications/SuperCollider.app/Contents/Resources/SCClassLibrary/Common/Control/NetAddr.sc</a></div><div id='superclasses'>Inherits from: <a href="../Classes/Object.html">Object</a></div>
<div id='subclasses'>Subclasses: <a href="../Classes/BundleNetAddr.html">BundleNetAddr</a></div>
<div id='related'>See also: <a href="./../Classes/OSCFunc.html">OSCFunc</a></div>
</div>
<div id='toc'>
<ul class='toc'><li class='toc1'><a href='#classmethods'>Class methods</a></li>
<ul class='toc'><li class='toc3'><a href='#*new'>new</a> </li>
<li class='toc3'><a href='#*fromIP'>fromIP</a> </li>
<li class='toc3'><a href='#*langPort'>langPort</a> </li>
<li class='toc3'><a href='#*localAddr'>localAddr</a> </li>
<li class='toc3'><a href='#*disconnectAll'>disconnectAll</a> </li>
<li class='toc3'><a href='#*broadcastFlag'>broadcastFlag</a> </li>
<li class='toc3'><a href='#*matchLangIP'>matchLangIP</a> </li>
<li class='toc2'><a href='#Inherited%20class%20methods'>Inherited class methods</a></li>
<li class='toc2'><a href='#Undocumented%20class%20methods'>Undocumented class methods</a></li>
<ul class='toc'><li class='toc3'><a href='#*localEndPoint'>localEndPoint</a> </li>
<li class='toc3'><a href='#*useDoubles'>useDoubles</a> </li>
</ul></ul><li class='toc1'><a href='#instancemethods'>Instance methods</a></li>
<ul class='toc'><li class='toc3'><a href='#-sendMsg'>sendMsg</a> </li>
<li class='toc3'><a href='#-sendBundle'>sendBundle</a> </li>
<li class='toc3'><a href='#-sendRaw'>sendRaw</a> </li>
<li class='toc3'><a href='#-connect'>connect</a> </li>
<li class='toc3'><a href='#-disconnect'>disconnect</a> </li>
<li class='toc3'><a href='#-ip'>ip</a> </li>
<li class='toc3'><a href='#-isLocal'>isLocal</a> </li>
<li class='toc2'><a href='#Inherited%20instance%20methods'>Inherited instance methods</a></li>
<li class='toc2'><a href='#Undocumented%20instance%20methods'>Undocumented instance methods</a></li>
<ul class='toc'><li class='toc3'><a href='#-=='>==</a> </li>
<li class='toc3'><a href='#-addr'>addr</a> </li>
<li class='toc3'><a href='#-hasBundle'>hasBundle</a> </li>
<li class='toc3'><a href='#-hash'>hash</a> </li>
<li class='toc3'><a href='#-hostname'>hostname</a> </li>
<li class='toc3'><a href='#-isConnected'>isConnected</a> </li>
<li class='toc3'><a href='#-makeSyncResponder'>makeSyncResponder</a> </li>
<li class='toc3'><a href='#-matches'>matches</a> </li>
<li class='toc3'><a href='#-port'>port</a> </li>
<li class='toc3'><a href='#-sendClumpedBundles'>sendClumpedBundles</a> </li>
<li class='toc3'><a href='#-sendStatusMsg'>sendStatusMsg</a> </li>
<li class='toc3'><a href='#-socket'>socket</a> </li>
<li class='toc3'><a href='#-sync'>sync</a> </li>
</ul></ul><li class='toc1'><a href='#examples'>Examples</a></li>
<ul class='toc'></ul></ul></div><h2><a class='anchor' name='classmethods'>Class Methods</a></h2>
<h3 class='cmethodname'><span class='methprefix'>*</span><a name='*new' href='./../Overviews/Methods.html#new'>new</a> (<span class='argstr'>hostname</span>, <span class='argstr'>port</span>)</h3>
<div class='method'>
<p>create new net address.<div class='note'><span class='notelabel'>NOTE:</span> To send messages internally, loopback IP is used: "127.0.0.1"</div><h4>Arguments:</h4>
<table class='arguments'>
<tr><td class='argumentname'>hostname<td class='argumentdesc'>
<p>a <a href="./../Classes/String.html">String</a>, either an IP number (e.g. "192.168.34.56") or a hostname such as "otherHost.local".<tr><td class='argumentname'>port<td class='argumentdesc'>
<p>a port number, like 57110.</table></div><h3 class='cmethodname'><span class='methprefix'>*</span><a name='*fromIP' href='./../Overviews/Methods.html#fromIP'>fromIP</a> (<span class='argstr'>addr</span>, <span class='argstr'>port</span>)</h3>
<div class='method'>
<p>create new net address using an integer IP number.</div><h3 class='cmethodname'><span class='methprefix'>*</span><a name='*langPort' href='./../Overviews/Methods.html#langPort'>langPort</a> </h3>
<div class='method'>
<p>Get the port sclang is currently listening on (may change after a recompile).</div><h3 class='cmethodname'><span class='methprefix'>*</span><a name='*localAddr' href='./../Overviews/Methods.html#localAddr'>localAddr</a> </h3>
<div class='method'>
<p>Get a NetAddr which corresponds to localhost and the port sclang is listening on.</div><h3 class='cmethodname'><span class='methprefix'>*</span><a name='*disconnectAll' href='./../Overviews/Methods.html#disconnectAll'>disconnectAll</a> </h3>
<div class='method'>
<p>close all TCP connections.</div><h3 class='cmethodname'><span class='methprefix'>*</span><a name='*broadcastFlag' href='./../Overviews/Methods.html#broadcastFlag'>broadcastFlag</a></h3>
<h3 class='cmethodname'><span class='methprefix'>*</span><a name='*broadcastFlag' href='./../Overviews/Methods.html#broadcastFlag'>broadcastFlag</a> = <span class='argstr'>flag: true</span></h3>
<div class='method'>
<p>Get or set the broadcast flag (whether or not broadcast messages can be sent).</div><h3 class='cmethodname'><span class='methprefix'>*</span><a name='*matchLangIP' href='./../Overviews/Methods.html#matchLangIP'>matchLangIP</a> (<span class='argstr'>ipstring</span>)</h3>
<div class='method'>
<p>Test an IP address to see if it matches that of one of the NICs on this computer.<h4>Arguments:</h4>
<table class='arguments'>
<tr><td class='argumentname'>ipstring<td class='argumentdesc'>
<p>A <a href="./../Classes/String.html">String</a> to test containing an IP number in dot decimal notation (e.g. "192.168.34.56").</table><h4>Returns:</h4>
<div class='returnvalue'>
<p>A <a href="./../Classes/Boolean.html">Boolean</a> indicating whether a match was found.</div></div><h3><a class='anchor' name='Inherited%20class%20methods'>Inherited class methods</a></h3>
<div id='inheritedclassmets'></div><h3><a class='anchor' name='Undocumented%20class%20methods'>Undocumented class methods</a></h3>
<h3 class='cmethodname'><span class='methprefix'>*</span><a name='*localEndPoint' href='./../Overviews/Methods.html#localEndPoint'>localEndPoint</a> </h3>
<h3 class='cmethodname'><span class='methprefix'>*</span><a name='*useDoubles' href='./../Overviews/Methods.html#useDoubles'>useDoubles</a> = <span class='argstr'>flag: false</span></h3>
<h2><a class='anchor' name='instancemethods'>Instance Methods</a></h2>
<h3 class='imethodname'><span class='methprefix'>-</span><a name='-sendMsg' href='./../Overviews/Methods.html#sendMsg'>sendMsg</a> ( <span class='argstr'>... args</span>)</h3>
<div class='method'>
<p>send a message without timestamp to the addr.</div><h3 class='imethodname'><span class='methprefix'>-</span><a name='-sendBundle' href='./../Overviews/Methods.html#sendBundle'>sendBundle</a> (<span class='argstr'>time</span> <span class='argstr'>... args</span>)</h3>
<div class='method'>
<p>send a bundle with timestamp to the addr.</div><h3 class='imethodname'><span class='methprefix'>-</span><a name='-sendRaw' href='./../Overviews/Methods.html#sendRaw'>sendRaw</a> (<span class='argstr'>rawArray</span>)</h3>
<div class='method'>
<p>send a raw message without timestamp to the addr.</div><h3 class='imethodname'><span class='methprefix'>-</span><a name='-connect' href='./../Overviews/Methods.html#connect'>connect</a> (<span class='argstr'>disconnectHandler</span>)</h3>
<div class='method'>
<p>open TCP connection.<h4>Arguments:</h4>
<table class='arguments'>
<tr><td class='argumentname'>disconnectHandler<td class='argumentdesc'>
<p>called when the connection is closed (either by the client or by the server).</table></div><h3 class='imethodname'><span class='methprefix'>-</span><a name='-disconnect' href='./../Overviews/Methods.html#disconnect'>disconnect</a> </h3>
<div class='method'>
<p>close TCP connection.</div><h3 class='imethodname'><span class='methprefix'>-</span><a name='-ip' href='./../Overviews/Methods.html#ip'>ip</a> </h3>
<div class='method'>
<p>returns the ip number (as a <a href="./../Classes/String.html">String</a>).<pre class='code prettyprint lang-sc'>n = NetAddr("localhost", 57110);
n.ip;</pre>
</div><h3 class='imethodname'><span class='methprefix'>-</span><a name='-isLocal' href='./../Overviews/Methods.html#isLocal'>isLocal</a> </h3>
<div class='method'>
<p>Test if this NetAddr ip number matches that of one of this hosts NICs, or the loopback address.<h4>Returns:</h4>
<div class='returnvalue'>
<p>A <a href="./../Classes/Boolean.html">Boolean</a>.</div></div><h3><a class='anchor' name='Inherited%20instance%20methods'>Inherited instance methods</a></h3>
<div id='inheritedinstmets'></div><h3><a class='anchor' name='Undocumented%20instance%20methods'>Undocumented instance methods</a></h3>
<h3 class='imethodname'><span class='methprefix'>-</span><a name='-==' href='./../Overviews/Methods.html#=='>==</a> (<span class='argstr'>that</span>)</h3>
<h3 class='imethodname'><span class='methprefix'>-</span><a name='-addr' href='./../Overviews/Methods.html#addr'>addr</a> </h3>
<h3 class='imethodname'><span class='methprefix'>-</span><a name='-hasBundle' href='./../Overviews/Methods.html#hasBundle'>hasBundle</a> </h3>
<h3 class='imethodname'><span class='methprefix'>-</span><a name='-hash' href='./../Overviews/Methods.html#hash'>hash</a> </h3>
<h3 class='imethodname'><span class='methprefix'>-</span><a name='-hostname' href='./../Overviews/Methods.html#hostname'>hostname</a></h3>
<h3 class='imethodname'><span class='methprefix'>-</span><a name='-hostname' href='./../Overviews/Methods.html#hostname'>hostname</a> = <span class='argstr'>inHostname</span></h3>
<h3 class='imethodname'><span class='methprefix'>-</span><a name='-isConnected' href='./../Overviews/Methods.html#isConnected'>isConnected</a> </h3>
<h3 class='imethodname'><span class='methprefix'>-</span><a name='-makeSyncResponder' href='./../Overviews/Methods.html#makeSyncResponder'>makeSyncResponder</a> (<span class='argstr'>condition</span>)</h3>
<h3 class='imethodname'><span class='methprefix'>-</span><a name='-matches' href='./../Overviews/Methods.html#matches'>matches</a> (<span class='argstr'>that</span>)</h3>
<h3 class='imethodname'><span class='methprefix'>-</span><a name='-port' href='./../Overviews/Methods.html#port'>port</a></h3>
<h3 class='imethodname'><span class='methprefix'>-</span><a name='-port' href='./../Overviews/Methods.html#port'>port</a> = value</h3>
<h3 class='imethodname'><span class='methprefix'>-</span><a name='-sendClumpedBundles' href='./../Overviews/Methods.html#sendClumpedBundles'>sendClumpedBundles</a> (<span class='argstr'>time</span> <span class='argstr'>... args</span>)</h3>
<h3 class='imethodname'><span class='methprefix'>-</span><a name='-sendStatusMsg' href='./../Overviews/Methods.html#sendStatusMsg'>sendStatusMsg</a> </h3>
<h3 class='imethodname'><span class='methprefix'>-</span><a name='-socket' href='./../Overviews/Methods.html#socket'>socket</a> </h3>
<h3 class='imethodname'><span class='methprefix'>-</span><a name='-sync' href='./../Overviews/Methods.html#sync'>sync</a> (<span class='argstr'>condition</span>, <span class='argstr'>bundles</span>, <span class='argstr'>latency</span>)</h3>
<h2><a class='anchor' name='examples'>Examples</a></h2>
<pre class='code prettyprint lang-sc'>n = NetAddr("127.0.0.1", 57120); // 57120 is sclang default port
r = OSCFunc({ arg msg, time; [time, msg].postln }, '/good/news', n);
n.sendMsg("/good/news", "you", "not you");
n.sendMsg("/good/news", 1, 1.3, 77);
n.sendBundle(0.2, ["/good/news", 1, 1.3, 77]);
r.free;
n.disconnect;
// note that different NetAddr objects with the same port and ip are independent.
r = OSCFunc({ "message arrived".postln }, '/x');
n = NetAddr("127.0.0.1", 57120);
n.sendMsg("/x")
u = NetAddr("127.0.0.1", 57120);
u.sendMsg("/x");
n.disconnect
u.sendMsg("/x");
r.free;
u.disconnect;</pre>
<div class='doclink'>helpfile source: <a href='file:///Applications/SuperCollider.app/Contents/Resources/HelpSource/Classes/NetAddr.schelp'>/Applications/SuperCollider.app/Contents/Resources/HelpSource/Classes/NetAddr.schelp</a><br>link::Classes/NetAddr::<br>sc version: 3.8.0</div></div></body></html>