receive udp packets on windows xp

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
 
C

Chris Smith

Andrew Chin said:
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):

I copied your code, ran it exactly as you have there, and it worked
fine. That is, it printed out "received packet" with the packet
information, and then exited. Windows XP, Java 1.5.0_04. Perhaps
you're doing something wrong in testing, such as getting the wrong IP
address for the Windows machine?

--
www.designacourse.com
The Easiest Way To Train Anyone... Anywhere.

Chris Smith - Lead Software Developer/Technical Trainer
MindIQ Corporation
 
A

Andrew Chin

well, this is rather embarrassing, but the issue turned out to be a
firewall issue.
despite the fact that java was (supposedly) allowed through the
firewall, the packet was apparently not getting through XP's built-in
firewall. because ethereal was seeing the packet, I assumed that the
firewall was not blocking it, but it looks like this was not a safe
assumption to make. Anyway, thanks for you help -- as the code worked
for you, i knew i should look at other potential problems beside the
code.

Thanks,
-Andrew Chin
 
R

Roedy Green

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):

try connecting your machines to the same LAN. If the code starts
working, you have a firewall problem. You might even have a software
firewall turned on in XP.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,020
Latest member
GenesisGai

Latest Threads

Top