A
Andrew Chin
Hi All,
I'm trying to write some Java code that receives UDP packets on a
specific port. I'm using jre1.5.0_06 on a windows XP pro machine. My
problem is that the code works on a Linux box, but not my Windows box.
Here is the code (which I modified from anohter Usenet post):
<code>
public static void main(String[] args) {
DatagramSocket socket;
try {
socket = new DatagramSocket(12345);
byte[] buf = new byte[256];
DatagramPacket packet = new DatagramPacket(buf, buf.length);
System.out.println("Attempting to receive packet...");
socket.receive(packet);
buf = packet.getData();
System.out.println("received packet: "+(new
String(buf)).substring(0,20) +
" from " + packet.getAddress() );
} catch (IOException e) {
e.printStackTrace();
}
}
</code>
I'm generating the udp packets with the following linux command:
nc -u 192.168.1.30 12345
Again, this code works fine under linux, but does not work under
Windows. Is this a known issue? Are there any workarounds or code
changes I need to make? (sending UDP packets under Windows works
fine).
Thanks,
-Andrew Chin
I'm trying to write some Java code that receives UDP packets on a
specific port. I'm using jre1.5.0_06 on a windows XP pro machine. My
problem is that the code works on a Linux box, but not my Windows box.
Here is the code (which I modified from anohter Usenet post):
<code>
public static void main(String[] args) {
DatagramSocket socket;
try {
socket = new DatagramSocket(12345);
byte[] buf = new byte[256];
DatagramPacket packet = new DatagramPacket(buf, buf.length);
System.out.println("Attempting to receive packet...");
socket.receive(packet);
buf = packet.getData();
System.out.println("received packet: "+(new
String(buf)).substring(0,20) +
" from " + packet.getAddress() );
} catch (IOException e) {
e.printStackTrace();
}
}
</code>
I'm generating the udp packets with the following linux command:
nc -u 192.168.1.30 12345
Again, this code works fine under linux, but does not work under
Windows. Is this a known issue? Are there any workarounds or code
changes I need to make? (sending UDP packets under Windows works
fine).
Thanks,
-Andrew Chin