Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / December 2005

Tip: Looking for answers? Try searching our database.

receive udp packets on windows xp

Thread view: 
Andrew Chin - 08 Dec 2005 02:37 GMT
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
Chris Smith - 08 Dec 2005 03:03 GMT
> 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?

Signature

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

Chris Smith - Lead Software Developer/Technical Trainer
MindIQ Corporation

Andrew Chin - 08 Dec 2005 03:37 GMT
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
Roedy Green - 08 Dec 2005 05:21 GMT
>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.
Signature

Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.