13 * pointing at the address and port number for the receiver. |
13 * pointing at the address and port number for the receiver. |
14 * |
14 * |
15 * When you want to send an OSC message, call send(). |
15 * When you want to send an OSC message, call send(). |
16 * |
16 * |
17 * An example based on com.illposed.osc.test.OSCPortTest::testMessageWithArgs() : |
17 * An example based on com.illposed.osc.test.OSCPortTest::testMessageWithArgs() : |
18 OSCPort sender = new OSCPort(); |
18 OSCPort sender = new OSCPort(); |
19 Object args[] = new Object[2]; |
19 Object args[] = new Object[2]; |
20 args[0] = new Integer(3); |
20 args[0] = new Integer(3); |
21 args[1] = "hello"; |
21 args[1] = "hello"; |
22 OSCMessage msg = new OSCMessage("/sayhello", args); |
22 OSCMessage msg = new OSCMessage("/sayhello", args); |
23 try { |
23 try { |
24 sender.send(msg); |
24 sender.send(msg); |
25 } catch (Exception e) { |
25 } catch (Exception e) { |
26 showError("Couldn't send"); |
26 showError("Couldn't send"); |
27 } |
27 } |
28 */ |
28 */ |
29 |
29 |
30 package com.illposed.osc; |
30 package com.illposed.osc; |
31 |
31 |
32 import java.net.*; |
32 import java.net.*; |
33 import java.io.IOException; |
33 import java.io.IOException; |
34 import com.illposed.osc.utility.OSCByteArrayToJavaConverter; |
34 import com.illposed.osc.utility.OSCByteArrayToJavaConverter; |
35 |
35 |
36 public class OSCPortOut extends OSCPort { |
36 public class OSCPortOut extends OSCPort { |
37 |
37 |
38 protected InetAddress address; |
38 protected InetAddress address; |
39 |
39 |
40 /** |
40 /** |
41 * Create an OSCPort that sends to newAddress, newPort |
41 * Create an OSCPort that sends to newAddress, newPort |
42 * @param newAddress InetAddress |
42 * @param newAddress InetAddress |
43 * @param newPort int |
43 * @param newPort int |
44 */ |
44 */ |
45 public OSCPortOut(InetAddress newAddress, int newPort) throws SocketException { |
45 public OSCPortOut(InetAddress newAddress, int newPort) throws SocketException { |
46 socket = new DatagramSocket(); |
46 socket = new DatagramSocket(); |
47 address = newAddress; |
47 address = newAddress; |
48 port = newPort; |
48 port = newPort; |
49 } |
49 } |
50 |
50 |
51 /** |
51 /** |
52 * Create an OSCPort that sends to newAddress, on the standard SuperCollider port |
52 * Create an OSCPort that sends to newAddress, on the standard SuperCollider port |
53 * @param newAddress InetAddress |
53 * @param newAddress InetAddress |
54 * |
54 * |
55 * Default the port to the standard one for SuperCollider |
55 * Default the port to the standard one for SuperCollider |
56 */ |
56 */ |
57 public OSCPortOut(InetAddress newAddress) throws SocketException { |
57 public OSCPortOut(InetAddress newAddress) throws SocketException { |
58 this(newAddress, defaultSCOSCPort); |
58 this(newAddress, defaultSCOSCPort); |
59 } |
59 } |
60 |
60 |
61 /** |
61 /** |
62 * Create an OSCPort that sends to localhost, on the standard SuperCollider port |
62 * Create an OSCPort that sends to localhost, on the standard SuperCollider port |
63 * Default the address to localhost |
63 * Default the address to localhost |
64 * Default the port to the standard one for SuperCollider |
64 * Default the port to the standard one for SuperCollider |
65 */ |
65 */ |
66 public OSCPortOut() throws UnknownHostException, SocketException { |
66 public OSCPortOut() throws UnknownHostException, SocketException { |
67 this(InetAddress.getLocalHost(), defaultSCOSCPort); |
67 this(InetAddress.getLocalHost(), defaultSCOSCPort); |
68 } |
68 } |
69 |
69 |
70 /** |
70 /** |
71 * @param aPacket OSCPacket |
71 * @param aPacket OSCPacket |
72 */ |
72 */ |
73 public void send(OSCPacket aPacket) throws IOException { |
73 public void send(OSCPacket aPacket) throws IOException { |
74 byte[] byteArray = aPacket.getByteArray(); |
74 byte[] byteArray = aPacket.getByteArray(); |
75 DatagramPacket packet = |
75 DatagramPacket packet = |
76 new DatagramPacket(byteArray, byteArray.length,address,port); |
76 new DatagramPacket(byteArray, byteArray.length,address,port); |
77 socket.send(packet); |
77 socket.send(packet); |
78 } |
78 } |
79 } |
79 } |