我正在尝试使用 JavaOsc,但在建立连接时遇到了困难。我的测试代码如下,但我输入的 IP 地址端口并不重要,它似乎连接(这是不正确的)并且我没有收到任何响应。所以我做错了什么,但很难找到文档。
final static private int port = 10023;
final static private String ipAddess = "192.168.1.78";
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
while(true) {
OSCPortOut sender = null;
OSCPortIn receiver = null;
try {
//receiver = new OSCPortIn(10023);
OSCMessageListener msgListener = new OSCMessageListener() {
@Override
public void acceptMessage(OSCMessageEvent oscMessageEvent) {
System.out.println("Message received A! " + oscMessageEvent.toString());
}
};
OSCPacketListener listener = new OSCPacketListener() {
@Override
public void handlePacket(OSCPacketEvent oscPacketEvent) {
System.out.println("Package received A! " + oscPacketEvent.toString());
}
@Override
public void handleBadData(OSCBadDataEvent oscBadDataEvent) {
System.out.println("Package BAD received B!");
}
public void acceptMessage(java.util.Date time, OSCMessage message) {
System.out.println("Message received!");
}
};
MessageSelector selector = new MessageSelector() {
@Override
public boolean isInfoRequired() {
System.out.println("Info required call");
return false;
}
@Override
public boolean matches(OSCMessageEvent oscMessageEvent) {
System.out.println("Message match?? " + oscMessageEvent.toString());
return false;
}
};
receiver = new OSCPortInBuilder().addPacketListener(listener).addMessageListener(selector, msgListener).setLocalPort(port).setRemotePort(port).build();
receiver.connect();
receiver.startListening();
sender = new OSCPortOut(InetAddress.getByName(ipAddess), port);
sender.connect();
System.out.println("Remote address: " + sender.getRemoteAddress() + " local: " + sender.getLocalAddress());
List<String> vars = new ArrayList<String>();
vars.add("/info");
OSCMessage msg = new OSCMessage("/msgAddress", vars);
System.out.println("Is connected: " + sender.isConnected());
sender.send(msg);
System.out.println("Msg info: " + msg.getInfo() + " - " + msg.getAddress());
System.out.println("Deamon: " + receiver.isDaemonListener() + " is listening " + receiver.isListening() + " is connected " + receiver.isConnected());
System.out.println("Please type 'q' to stop.");
if(scanner.nextLine().equalsIgnoreCase("q")) break;
} catch (Exception e) {
System.out.println("Error: " + e.getMessage());
e.printStackTrace(System.out);
} finally {
try {
if (sender != null) sender.close();
if (receiver != null) receiver.close();
} catch (IOException e){
System.out.println("Problem closing: " + e.getMessage());
}
}
}
System.out.println("Finished.");
回应是:
Info required
Remote address: /192.168.1.78:10023 local: /0.0.0.0:0
Is connected: true
Msg info: null - /msgAddress
Deamon: true is listening true is connected true
Please type 'q' to stop.
我还尝试联系本地接收器(使用 127.0.0.1),但也没有用。任何建议将不胜感激!