forked from processing/processing
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOSCPortOut.java
More file actions
84 lines (76 loc) · 2.14 KB
/
Copy pathOSCPortOut.java
File metadata and controls
84 lines (76 loc) · 2.14 KB
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
/*
* Copyright (C) 2004-2006, C. Ramakrishnan / Illposed Software.
* All rights reserved.
*
* This code is licensed under the BSD 3-Clause license.
* See file LICENSE (or LICENSE.html) for more information.
*/
package com.illposed.osc;
import java.io.IOException;
import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.InetAddress;
import java.net.SocketException;
import java.net.UnknownHostException;
/**
* OSCPortOut is the class that sends OSC messages
* to a specific address and port.
*
* To send an OSC message, call send().
*
* An example based on
* {@link com.illposed.osc.OSCPortTest#testMessageWithArgs()}:
* <pre>
OSCPort sender = new OSCPort();
Object args[] = new Object[2];
args[0] = new Integer(3);
args[1] = "hello";
OSCMessage msg = new OSCMessage("/sayhello", args);
try {
sender.send(msg);
} catch (Exception e) {
showError("Couldn't send");
}
* </pre>
*
* @author Chandrasekhar Ramakrishnan
*/
public class OSCPortOut extends OSCPort {
private InetAddress address;
/**
* Create an OSCPort that sends to address:port.
* @param address the UDP address to send to
* @param port the UDP port to send to
*/
public OSCPortOut(InetAddress address, int port)
throws SocketException
{
super(new DatagramSocket(), port);
this.address = address;
}
/**
* Create an OSCPort that sends to address,
* using the standard SuperCollider port.
* @param address the UDP address to send to
*/
public OSCPortOut(InetAddress address) throws SocketException {
this(address, DEFAULT_SC_OSC_PORT);
}
/**
* Create an OSCPort that sends to "localhost",
* on the standard SuperCollider port.
*/
public OSCPortOut() throws UnknownHostException, SocketException {
this(InetAddress.getLocalHost(), DEFAULT_SC_OSC_PORT);
}
/**
* Send an OSC packet (message or bundle) to the receiver we are bound to.
* @param aPacket the bundle or message to send
*/
public void send(OSCPacket aPacket) throws IOException {
byte[] byteArray = aPacket.getByteArray();
DatagramPacket packet =
new DatagramPacket(byteArray, byteArray.length, address, getPort());
getSocket().send(packet);
}
}