SuperCollider CLASSES

NetAddr

network address
Inherits from: Object
Subclasses: BundleNetAddr

Class Methods

*new (hostname, port)

create new net address.

NOTE: To send messages internally, loopback IP is used: "127.0.0.1"

Arguments:

hostname

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

port

a port number, like 57110.

*fromIP (addr, port)

create new net address using an integer IP number.

*langPort

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

*localAddr

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

*disconnectAll

close all TCP connections.

*broadcastFlag

*broadcastFlag = flag: true

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

*matchLangIP (ipstring)

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

Arguments:

ipstring

A String to test containing an IP number in dot decimal notation (e.g. "192.168.34.56").

Returns:

A Boolean indicating whether a match was found.

Inherited class methods

Undocumented class methods

*localEndPoint

*useDoubles = flag: false

Instance Methods

-sendMsg ( ... args)

send a message without timestamp to the addr.

-sendBundle (time ... args)

send a bundle with timestamp to the addr.

-sendRaw (rawArray)

send a raw message without timestamp to the addr.

-connect (disconnectHandler)

open TCP connection.

Arguments:

disconnectHandler

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

-disconnect

close TCP connection.

-ip

returns the ip number (as a String).

n = NetAddr("localhost", 57110);
n.ip;

-isLocal

Test if this NetAddr ip number matches that of one of this hosts NICs, or the loopback address.

Returns:

Inherited instance methods

Undocumented instance methods

-== (that)

-addr

-hasBundle

-hash

-hostname

-hostname = inHostname

-isConnected

-makeSyncResponder (condition)

-matches (that)

-port

-port = value

-sendClumpedBundles (time ... args)

-sendStatusMsg

-socket

-sync (condition, bundles, latency)

-tryConnectTCP (onComplete, onFailure, maxAttempts: 10)

-tryDisconnectTCP (onComplete, onFailure)

Examples

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;