Include a header file required for build on mac 10.4
[supercollider.git] / Help / Control / NetAddr.html
blob05fb3674582830f51c4482240ad63797286cb98d
1 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
2 <html>
3 <head>
4 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
5 <meta http-equiv="Content-Style-Type" content="text/css">
6 <title></title>
7 <meta name="Generator" content="Cocoa HTML Writer">
8 <meta name="CocoaVersion" content="824.41">
9 <style type="text/css">
10 p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica}
11 p.p2 {margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica; min-height: 14.0px}
12 p.p3 {margin: 0.0px 0.0px 0.0px 0.0px; font: 9.0px Monaco}
13 p.p4 {margin: 0.0px 0.0px 0.0px 0.0px; font: 9.0px Monaco; min-height: 12.0px}
14 p.p5 {margin: 0.0px 0.0px 0.0px 0.0px; font: 9.0px Monaco; color: #bf0000}
15 p.p6 {margin: 0.0px 0.0px 0.0px 0.0px; font: 9.0px Monaco; color: #000000; min-height: 12.0px}
16 p.p7 {margin: 0.0px 0.0px 0.0px 0.0px; font: 9.0px Monaco; color: #000000}
17 p.p8 {margin: 0.0px 0.0px 0.0px 0.0px; font: 9.0px Monaco; color: #606060}
18 span.s1 {font: 18.0px Helvetica}
19 span.s2 {font: 9.0px Monaco}
20 span.s3 {font: 12.0px Helvetica}
21 span.s4 {color: #000000}
22 span.s5 {color: #0000bf}
23 span.s6 {color: #606060}
24 span.s7 {color: #007300}
25 span.Apple-tab-span {white-space:pre}
26 </style>
27 </head>
28 <body>
29 <p class="p1"><span class="s1"><b>NetAddr</b></span><span class="s2"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span></span><b>network address</b></p>
30 <p class="p2"><br></p>
31 <p class="p1">superclass: Object</p>
32 <p class="p2"><br></p>
33 <p class="p2"><br></p>
34 <p class="p1"><span class="Apple-tab-span"> </span><b>*new(hostname, port)</b><span class="Apple-tab-span"> </span>create new net address.<span class="Apple-converted-space"> </span></p>
35 <p class="p1"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>Hostname is a string, either an ip number (e.g. <i>"192.168.34.56"</i>) or a hostname such as <i>"otherHost.local"</i>.</p>
36 <p class="p1"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>Port is a port number, like <i>57110</i>.</p>
37 <p class="p1"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>Note: to send messages internally, loopback ip is used: <i>"127.0.0.1"</i></p>
38 <p class="p2"><span class="Apple-tab-span"> </span></p>
39 <p class="p1"><span class="Apple-tab-span"> </span><b>*fromIP(ip, port)</b><span class="Apple-tab-span"> </span><span class="Apple-tab-span">create new net address using an integer ip number.</span></p>
40 <p class="p2"><span class="Apple-tab-span"> </span></p>
41 <p class="p1"><span class="Apple-tab-span"> </span><b>*langPort</b><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>Get the port sclang is currently listening on (may change after a recompile).</p>
42 <p class="p2"><span class="Apple-tab-span"> </span></p>
43 <p class="p1"><span class="Apple-tab-span"> </span><b>*localAddr</b><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>Get a NetAddr which corresponds to localhost and the port sclang is listening on.</p>
44 <p class="p2"><span class="Apple-tab-span"> </span></p>
45 <p class="p1"><span class="Apple-tab-span"> </span><b>sendMsg(args...)</b><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>send a message without timestamp to the addr.</p>
46 <p class="p2"><span class="Apple-tab-span"> </span></p>
47 <p class="p1"><span class="Apple-tab-span"> </span><b>sendBundle(timestamp, args...)</b><span class="Apple-tab-span"> </span>send a bundle with timestamp to the addr.</p>
48 <p class="p2"><span class="Apple-tab-span"> </span></p>
49 <p class="p1"><span class="Apple-tab-span"> </span><b>sendRaw(rawArray)</b><span class="Apple-tab-span"> </span>send a raw message without timestamp to the addr.</p>
50 <p class="p2"><span class="Apple-tab-span"> </span></p>
51 <p class="p1"><span class="Apple-tab-span"> </span><b>connect(disconnectHandler)</b><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>open TCP connection. <b>disconnectHandler</b> is called when</p>
52 <p class="p1"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>the connection is closed (either by the client or by the server)</p>
53 <p class="p2"><span class="Apple-tab-span"> </span></p>
54 <p class="p1"><span class="Apple-tab-span"> </span><b>disconnect</b><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>close TCP connection</p>
55 <p class="p2"><span class="Apple-tab-span"> </span></p>
56 <p class="p1"><span class="Apple-tab-span"> </span><b>ip </b><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>returns the ip number (as string)</p>
57 <p class="p1"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>example:<span class="Apple-converted-space"> </span></p>
58 <p class="p3"><span class="s3"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span></span>n = NetAddr("localhost", 57110);</p>
59 <p class="p3"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>n.ip;</p>
60 <p class="p4"><span class="Apple-tab-span"> </span></p>
61 <p class="p1"><b><span class="Apple-tab-span"> </span>*disconnectAll<span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span></b>close all TCP connections</p>
62 <p class="p2"><span class="Apple-tab-span"> </span></p>
63 <p class="p1"><b><span class="Apple-tab-span"> </span>*broadcastFlag<span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span></b>check broadcast flag</p>
64 <p class="p2"><span class="Apple-tab-span"> </span></p>
65 <p class="p1"><b><span class="Apple-tab-span"> </span>*broadcastFlag_( flag )<span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span></b>Sets the broadcast flag (whether or not broadcast messages can be sent)</p>
66 <p class="p2"><span class="Apple-tab-span"> </span></p>
67 <p class="p1"><b><span class="Apple-tab-span"> </span>*useDoubles_( flag )<span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span></b></p>
68 <p class="p2"><span class="Apple-tab-span"> </span></p>
69 <p class="p4"><br></p>
70 <p class="p4"><br></p>
71 <p class="p5">// example</p>
72 <p class="p6"><br></p>
73 <p class="p6"><br></p>
74 <p class="p5"><span class="s4">n = </span><span class="s5">NetAddr</span><span class="s4">(</span><span class="s6">"127.0.0.1"</span><span class="s4">, 57120); </span>// 57120 is sclang default port</p>
75 <p class="p7">r = <span class="s5">OSCresponder</span>(n, <span class="s7">'/good/news'</span>, { <span class="s5">arg</span> time, resp, msg; [time, msg].postln }).add;</p>
76 <p class="p6"><br></p>
77 <p class="p8"><span class="s4">n.sendMsg(</span>"/good/news"<span class="s4">, </span>"you"<span class="s4">, </span>"not you"<span class="s4">);</span></p>
78 <p class="p7">n.sendMsg(<span class="s6">"/good/news"</span>, 1, 1.3, 77);</p>
79 <p class="p6"><br></p>
80 <p class="p6"><br></p>
81 <p class="p7">n.sendBundle(0.2, [<span class="s6">"/good/news"</span>, 1, 1.3, 77]);</p>
82 <p class="p6"><br></p>
83 <p class="p7">r.remove;</p>
84 <p class="p7">n.disconnect;</p>
85 <p class="p6"><br></p>
86 <p class="p5">// note that different NetAddr objects with the same port and ip are independent.</p>
87 <p class="p6"><br></p>
88 <p class="p7">r = <span class="s5">OSCresponder</span>(<span class="s5">nil</span>, <span class="s7">'/x'</span>, { <span class="s6">"message arrived"</span>.postln }).add;</p>
89 <p class="p6"><br></p>
90 <p class="p7">n = <span class="s5">NetAddr</span>(<span class="s6">"127.0.0.1"</span>, 57120);</p>
91 <p class="p7">n.sendMsg(<span class="s6">"/x"</span>)</p>
92 <p class="p6"><br></p>
93 <p class="p6"><br></p>
94 <p class="p7">u = <span class="s5">NetAddr</span>(<span class="s6">"127.0.0.1"</span>, 57120);</p>
95 <p class="p7">u.sendMsg(<span class="s6">"/x"</span>);</p>
96 <p class="p6"><br></p>
97 <p class="p7">n.disconnect</p>
98 <p class="p6"><br></p>
99 <p class="p7">u.sendMsg(<span class="s6">"/x"</span>);</p>
100 <p class="p6"><br></p>
101 <p class="p7">r.remove;</p>
102 <p class="p7">u.disconnect;</p>
103 <p class="p6"><br></p>
104 <p class="p6"><br></p>
105 <p class="p6"><br></p>
106 </body>
107 </html>