Include a header file required for build on mac 10.4
[supercollider.git] / Help / Libraries / JITLib / tutorials / jitlib_networking.html
bloba9e26634ed230f458cc586c7c77c2b51a5c28b02
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: 18.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: 12.0px Helvetica}
13 p.p4 {margin: 0.0px 0.0px 0.0px 0.0px; font: 9.0px Monaco}
14 p.p5 {margin: 0.0px 0.0px 0.0px 0.0px; font: 9.0px Monaco; color: #a3220e}
15 p.p6 {margin: 0.0px 0.0px 0.0px 0.0px; font: 9.0px Monaco; min-height: 12.0px}
16 p.p7 {margin: 0.0px 0.0px 0.0px 0.0px; font: 9.0px Monaco; color: #a3220e; min-height: 12.0px}
17 span.s1 {font: 12.0px Helvetica}
18 span.s2 {color: #0028b7}
19 span.s3 {color: #606060}
20 span.s4 {color: #0000ff}
21 span.s5 {font: 12.0px Helvetica; color: #000000}
22 span.s6 {color: #000000}
23 span.s7 {font: 9.0px Monaco}
24 span.s8 {color: #a3220e}
25 span.s9 {font: 9.0px Monaco; color: #a3220e}
26 span.s10 {color: #002aff}
27 span.Apple-tab-span {white-space:pre}
28 </style>
29 </head>
30 <body>
31 <p class="p1"><b>networked programming</b><span class="s1"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span></span></p>
32 <p class="p2"><br></p>
33 <p class="p3"><i>please note any problems, I'll try to add solutions here.</i></p>
34 <p class="p2"><br></p>
35 <p class="p2"><br></p>
36 <p class="p3"><b>1) using ProxySpace with more than one client, with separate bus spaces</b></p>
37 <p class="p2"><br></p>
38 <p class="p3"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><i>Note:</i> <span class="Apple-tab-span"> </span>if only one client is using a remote server, only step (a) and step (d) are relevant.<span class="Apple-converted-space"> </span></p>
39 <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>The clientID argument can be left out then.</p>
40 <p class="p2"><span class="Apple-tab-span"> </span></p>
41 <p class="p3"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><i>before you start:</i></p>
42 <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>remember to synchronize your system clocks. This can be done by:</p>
43 <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>in OS X: SystemPreferences&gt;Date&amp;Time: set<i> "Set Date &amp; Time automatically"<span class="Apple-converted-space">  </span></i>to true.</p>
44 <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>in linux: set the ntp clock</p>
45 <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>a local time server is better than the apple time server.</p>
46 <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>if you cannot sync the time, you can set the server latency to nil.</p>
47 <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>This will break the pattern's functionality though.</p>
48 <p class="p2"><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></p>
49 <p class="p2"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span></p>
50 <p class="p3"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>a) boot the (remote) server and create a local model</p>
51 <p class="p3"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>(you cannot directly boot a remote server instance)</p>
52 <p class="p2"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span></p>
53 <p class="p4"><span class="s1"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span></span>s = <span class="s2">Server</span>(<span class="s3">"serverName"</span>, <span class="s2">NetAddr</span>(hostname, port), clientID);</p>
54 <p class="p2"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span></p>
55 <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><b>serverName</b> <span class="Apple-tab-span"> </span>can be any name</p>
56 <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><b>hostname</b> <span class="Apple-tab-span"> </span>is an ip address, or if you have a name resolution, a network name</p>
57 <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><b>port</b> <span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>the port on which the server is listening. default is 57110</p>
58 <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><b>clientID</b><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>for each client (each sc-lang) <i>a different integer number has to be given</i><span class="Apple-converted-space"> </span></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>see <a href="../../../ServerArchitecture/Server.html"><span class="s4">Server</span></a></p>
60 <p class="p2"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span></p>
61 <p class="p3"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>b) from each client, initialize the default node and set notify to true:</p>
62 <p class="p2"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-converted-space"> <span class="Apple-tab-span"> </span></span></p>
63 <p class="p5"><span class="s5"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span> </span><span class="s6"><span class="Apple-tab-span"> </span>s.boot; </span>// this will initialize the tree and start notification</p>
64 <p class="p6"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-converted-space"> <span class="Apple-tab-span"> </span></span></p>
65 <p class="p5"><span class="s6"><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>// if needed, a server window can be created:</p>
66 <p class="p4"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span> <span class="Apple-tab-span"> </span>s.makeWindow;</p>
67 <p class="p2"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span></p>
68 <p class="p3"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>c) preallocate a range of busses in each client.<span class="Apple-converted-space"> </span></p>
69 <p class="p3"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>If there is conflicts, increase the number of busses in the server options before booting:<span class="s7"> <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 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>(s.options.numAudioBusChannels = 1024;)</span></p>
70 <p class="p2"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span></p>
71 <p class="p4"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>(</p>
72 <p class="p4"><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="s2">var</span> numberOfParticipants, n;</p>
73 <p class="p4"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>numberOfParticipants = 4;</p>
74 <p class="p6"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span></p>
75 <p class="p6"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span></p>
76 <p class="p4"><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 = s.options.numAudioBusChannels / numberOfParticipants;</p>
77 <p class="p4"><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 = n.floor.asInteger * s.clientID;</p>
78 <p class="p4"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>s.audioBusAllocator.alloc(n);</p>
79 <p class="p6"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span></p>
80 <p class="p6"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span></p>
81 <p class="p4"><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 = s.options.numControlBusChannels / numberOfParticipants;</p>
82 <p class="p4"><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 = n.floor.asInteger * s.clientID;</p>
83 <p class="p4"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>s.controlBusAllocator.alloc(n);</p>
84 <p class="p4"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>)</p>
85 <p class="p6"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span></p>
86 <p class="p6"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span></p>
87 <p class="p3"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>d) now create a ProxySpace from the server:</p>
88 <p class="p2"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span></p>
89 <p class="p4"><span class="s1"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span></span><span class="Apple-tab-span"> </span>p = <span class="s2">ProxySpace</span>.push(s);<span class="s1"><span class="Apple-converted-space"> </span></span></p>
90 <p class="p2"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span></p>
91 <p class="p2"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span></p>
92 <p class="p3"><b>2) using ProxySpace with more than one client, with a partly shared bus space</b></p>
93 <p class="p2"><b><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span></b></p>
94 <p class="p3"><b><span class="Apple-tab-span"> </span></b><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>step a, b like in (1), skip (d)</p>
95 <p class="p2"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span></p>
96 <p class="p3"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>c) before allocating a number of busses for each client, create shared busses:</p>
97 <p class="p4"><span class="s1"><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>p = <span class="s2">ProxySpace</span>.push(s);</p>
98 <p class="p4"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>~shared1.ar(2);</p>
99 <p class="p4"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>~shared2.ar(2);</p>
100 <p class="p4"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>~sharedkr.kr(1); <span class="s8">// or other names.</span></p>
101 <p class="p7"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span></p>
102 <p class="p3"><span class="s9"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span></span>then do (c) like in (1), just take care that the shared busses are taking number space</p>
103 <p class="p3"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>already, so the easiest is to increase the numberOfParticipants by one, so no overrun</p>
104 <p class="p3"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>happens.</p>
105 <p class="p6"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span></p>
106 <p class="p6"><br></p>
107 <p class="p6"><br></p>
108 <p class="p2"><br></p>
109 <p class="p2"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span></p>
110 <p class="p3"><b>3) writing a chat</b></p>
111 <p class="p2"><span class="Apple-tab-span"> </span></p>
112 <p class="p3"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>see example in<b> </b><a href="../networking/Client.html"><span class="s10">Client</span></a></p>
113 <p class="p2"><b><span class="Apple-tab-span"> </span></b></p>
114 <p class="p2"><b><span class="Apple-tab-span"> </span></b></p>
115 <p class="p2"><b><span class="Apple-tab-span"> </span></b></p>
116 <p class="p3"><b>see also </b><a href="../networking/Public.html"><span class="s10">Public</span></a></p>
117 <p class="p2"><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></p>
118 <p class="p2"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span></p>
119 </body>
120 </html>