我有一个在本地机器上工作的处理程序。它从本地 udp 端口读取数据并使用这些数据在我的屏幕上绘制圆圈。它起作用了,太好了。
但在生产中,程序必须在另一台计算机上运行。我无法让它工作。处理向我显示此错误消息:
opening socket failed!
> address:192.168.1.118, port:6666 [group:null]
> Cannot assign requested address: Cannot bind
当然,我检查了 IP 地址,这些都可以,因为它在本地机器上运行良好。这是我的 UDP 部分代码:
// import UDP library
import hypermedia.net.*;
String HOST_IP = "192.168.1.118";
UDP udp; // define the UDP object
// get an array ready
int num = 20;
int[] xx = new int[num];
int[] yy = new int[num];
void setup() {
size(1024, 768);
smooth();
//noStroke();
// create a new datagram connection on port 6666
udp = new UDP(this, 6666, HOST_IP);
udp.listen( true );
}
//process events
void draw() {;}
/**
* To perform any action on datagram reception, you need to implement this
* handler in your code. This method will be automatically called by the UDP
* object each time he receive a nonnull message.
* By default, this method have just one argument (the received message as
* byte[] array), but in addition, two arguments (representing in order the
* sender IP address and his port) can be set like below.
*/
// void receive( byte[] data ) { // <-- default handler
void receive( byte[] data ) {
background(255);
// get the "real" message =
// forget the ";\n" at the end <-- !!! only for a communication with Pd !!!
data = subset(data, 0, data.length-2);
String message = new String( data );
// print the result
println(message );
在两台机器上我都使用 Windows XP 并且它们通过交换机和 udp 电缆连接。
我不知道从哪里开始故障排除以及如何进行。有任何想法吗?