| 1 |
import java.awt.event.*; |
|---|
| 2 |
import java.util.*; |
|---|
| 3 |
import java.awt.*; |
|---|
| 4 |
import java.io.*; |
|---|
| 5 |
import java.net.*; |
|---|
| 6 |
|
|---|
| 7 |
/** |
|---|
| 8 |
* |
|---|
| 9 |
* Gateway |
|---|
| 10 |
* <BR><BR> |
|---|
| 11 |
* OpenSoundControl / Flash Gateway Server. |
|---|
| 12 |
* |
|---|
| 13 |
* Usage: java Gateway [oscPort] [flashPort] |
|---|
| 14 |
* |
|---|
| 15 |
* @author Ben Chun ben@benchun.net |
|---|
| 16 |
* @version 1.0 |
|---|
| 17 |
*/ |
|---|
| 18 |
|
|---|
| 19 |
public class Gateway { |
|---|
| 20 |
private OscServer oscServer; |
|---|
| 21 |
private TcpServer tcpServer; |
|---|
| 22 |
|
|---|
| 23 |
/** |
|---|
| 24 |
* Constructor for the Gateway. |
|---|
| 25 |
* @param flashPort TCP port for Flash client connections. |
|---|
| 26 |
* @param oscPort UDP port for OSC communication. |
|---|
| 27 |
*/ |
|---|
| 28 |
public Gateway(int oscPort, int flashPort) { |
|---|
| 29 |
System.out.println("Attempting to start OSC / Flash Gateway server"); |
|---|
| 30 |
// --- create the servers |
|---|
| 31 |
oscServer = new OscServer(oscPort, this); |
|---|
| 32 |
tcpServer = new TcpServer(flashPort, this); |
|---|
| 33 |
// --- start their threads |
|---|
| 34 |
oscServer.start(); |
|---|
| 35 |
tcpServer.start(); |
|---|
| 36 |
} |
|---|
| 37 |
|
|---|
| 38 |
/** |
|---|
| 39 |
* Broadcasts a message too all connected TCP clients. |
|---|
| 40 |
* |
|---|
| 41 |
* @param message The message to broadcast. |
|---|
| 42 |
*/ |
|---|
| 43 |
public void broadcastMessage(String message) { |
|---|
| 44 |
tcpServer.broadcastMessage(message); |
|---|
| 45 |
} |
|---|
| 46 |
|
|---|
| 47 |
/** |
|---|
| 48 |
* Sends a packet to an OSC client via UDP. |
|---|
| 49 |
* |
|---|
| 50 |
* @param packet The packet to send. |
|---|
| 51 |
*/ |
|---|
| 52 |
public void sendPacket(OscPacket packet) { |
|---|
| 53 |
Debug.writeActivity("Gateway transporting OSC packet."); |
|---|
| 54 |
oscServer.sendPacket(packet); |
|---|
| 55 |
} |
|---|
| 56 |
|
|---|
| 57 |
public static void main(String args[]) { |
|---|
| 58 |
// --- if correct number of arguments |
|---|
| 59 |
if(args.length == 2) { |
|---|
| 60 |
Gateway myGateway = new Gateway( Integer.parseInt(args[0]), |
|---|
| 61 |
Integer.parseInt(args[1]) ); |
|---|
| 62 |
} else { |
|---|
| 63 |
// otherwise give correct usage |
|---|
| 64 |
System.out.println("Usage: java Gateway [oscPort] [flashPort]"); |
|---|
| 65 |
} |
|---|
| 66 |
} |
|---|
| 67 |
} |
|---|