Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9170513
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T16:01:55+00:00 2026-06-17T16:01:55+00:00

I have the following problem: I have an extremely simple Java Datagram client and

  • 0

I have the following problem:

I have an extremely simple Java Datagram client and server located on a remote machine. And the client will not receive anything from the server unless it sent a packet to the server earlier(it doesn’t matter what information did the packet hold)

Here is what my client looks like:

    public static void TheClient() throws Exception { 
        ds = new DatagramSocket(clientPort); 
        while(true) { 
            DatagramPacket p = new DatagramPacket(buffer, buffer.length);   
            ds.receive(p); 
            System.out.println(new String(p.getData(), 0, p.getLength())); 
        } 
    } 

Basically all it does is listen on port clientPort and then prints whatever it receives. However it does not work.

Now slightly modifying it solves the problem:

public static void TheClient() throws Exception {
    ds = new DatagramSocket(clientPort); 

    //Sending an empty packet
    byte tempBuffer1[] = new byte[10];
    InetAddress address = InetAddress.getByName(SERVER_IP);
    DatagramPacket packet1 = new DatagramPacket(
            tempBuffer1, tempBuffer1.length, address, serverPort);
    ds.send(packet1);

    while(true) { 
        DatagramPacket p = new DatagramPacket(buffer, 
                buffer.length);     
        ds.receive(p); 
        System.out.println(new String(p.getData(), 0, 
                p.getLength())); 
    } 
} 

Does anyone know what might be causing this problem? While the workaround did solve the problem it doesn’t make any sense to me why it wouldn’t work originally so the solution might not actually work on all the computers.

Also, it should be noted that the code works fine when both the client and the server are on the same machine.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T16:01:56+00:00Added an answer on June 17, 2026 at 4:01 pm

    Check to see if your PC is using a private IP address, typically one starting with either “10.x.x.x” or “192.168.x.x”. If so, the most likely cause is that you’re using a NAT-based firewall which shares a single public address and multiple private addresses.

    When you send a packet outbound, the firewall knows which internal address should receive the return packet. When a connection is initiated from an external address, however, it has no way of knowing what internal address should receive the traffic. Most SOHO (small office / home office) routers will allow you to “port forward” traffic to a specific internal IP address. If you’re using DHCP, you’ll want to assign yourself a static IP address or your port forwarding may stop working at some future date because it grabs a different IP address.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using GWT/JAVA for development. I have following problem: I want to remove
I have the following problem, from c++ I send huge string[] to java. huge
I have the following problem: I am creating a simple plugin jquery carousel, to
I have the following situation: .net 3.5 WinForm client app accessing SQL Server 2008
I have an extremely simple JSON object that looks like the following: var data
I have the following extremely simple Mocha / Chai test: describe('main tests', function ()
I have following problem: I have to make a ASP.NET Webapplication with a two-row
I have following problem: I have built a tabbar application with 4 tabs. I
I have following problem, Code: String a=Yeahh, I have no a idea what's happening
Hi i have following Problem. I write a Mediawiki Extension where i need some

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.