File: NetAddr.schelp

package info (click to toggle)
supercollider 1%3A3.10.0%2Brepack-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 45,496 kB
  • sloc: cpp: 283,513; lisp: 74,040; ansic: 72,252; sh: 23,016; python: 7,175; makefile: 1,087; perl: 766; java: 677; yacc: 314; lex: 175; ruby: 136; objc: 65; xml: 15
file content (125 lines) | stat: -rw-r--r-- 3,230 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
class:: NetAddr
summary:: network address
related:: Classes/OSCFunc
categories:: Control, External Control>OSC

ClassMethods::

private::initClass

method::new
create new net address.
note::To send messages internally, loopback IP is used: "127.0.0.1"::

argument::hostname
a link::Classes/String::, either an IP number (e.g. "192.168.34.56") or a hostname such as "otherHost.local".

argument::port
a port number, like 57110.

method::fromIP
create new net address using an integer IP number.

method::langPort
Get the port sclang is currently listening on (may change after a recompile).

method::localAddr
Get a NetAddr which corresponds to localhost and the port sclang is listening on.

method::disconnectAll
close all TCP connections.

method::broadcastFlag
Get or set the broadcast flag (whether or not broadcast messages can be sent).

method::matchLangIP
Test an IP address to see if it matches that of one of the NICs on this computer.

argument::ipstring
A link::Classes/String:: to test containing an IP number in dot decimal notation (e.g. "192.168.34.56").

returns::A link::Classes/Boolean:: indicating whether a match was found.

InstanceMethods::

private::prConnect, prDisconnect, prConnectionClosed, recover

method::sendMsg
Convert the argument list to an OSC message and send it to the NetAddr without a timestamp. The first argument is the OSC address, and the remaining arguments are the arguments in the OSC message. If you leave off the initial "/" in the OSC address, one will be prepended. The technical details of how sclang objects are converted to OSC messages is given in the link::Guides/OSC_communication:: helpfile.

code::
n = NetAddr("localhost", 12345);
n = s.addr;

// Example sending symbols, integers, and a float
n.sendMsg('/s_new', \default, 2000, 0, s.defaultGroup.nodeID, \freq, 60.midicps);

// The initial forward slash can be omitted
n.sendMsg(\n_set, 2000, \gate, 0);

// Using the performList syntax, you can use an array to store an OSC message
~msg = [\n_set, 2000, \gate, 0];
n.sendMsg(*~msg);
::

method::sendBundle
send a bundle with timestamp to the addr.

method::sendRaw
send a raw message without timestamp to the addr.

method::connect
open TCP connection.

argument::disconnectHandler
called when the connection is closed (either by the client or by the server).

method::disconnect
close TCP connection.

method::ip
returns the ip number (as a link::Classes/String::).
code::
n = NetAddr("localhost", 57110);
n.ip;
::

method::isLocal
Test if this NetAddr ip number matches that of one of this hosts NICs, or the loopback address.
returns::A link::Classes/Boolean::.

Examples::

code::
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;
::