views:

279

answers:

1

Hi!

I'm creating a server(now called Server1) which is communicating with another server i've got(now called Server2).

  • Server1 sends a datagrampackage to Server2.
  • Server2 is supposed to send two datagram packages back, but i only get one back.
  • Server2 is not the problem, and sends two packages.

I use Wireshark to sniff the packages that leaves and comes to Server1.

Package one(from wireshark): "5955 11994.023974 192.168.1.3 192.168.1.2 UDP Source port: 50000 Destination port: 50004"

Package two(from wireshark): 5958 11994.045830 192.168.1.3 192.168.1.2 ICMP Destination unreachable (Port unreachable)

Server1 runs a Thread which is listening for datagram packages.

Code Server1:

     while (m_keepRunning)
    {
        try
        {
         TermMsg receivedMessage = null;
         receivedMessage = receive();   //See this function further down
         if (receivedMessage != null)
            {
                if (receivedMessage.getMsgType().equals(TermMsgType.ACK))
                {
                 System.out.println("This is an ack!");
                }
                else
                {

                 System.out.println("This is a response");
                }
            }
         else
         {
          System.out.println("This is nothing");
         }

        }

Receive function:

      private TermMsg receive() throws IOException, TermMsgException
{
  byte[] inBuf = new byte[BUF_SIZE_RX];
  DatagramPacket inData = new DatagramPacket(inBuf, BUF_SIZE_RX);

    if(true == firstEncounter)
    {
            StartMessage startReq = getStartMsg(false);
     DatagramPacket p = makeDatagramP(startReq);
     socket.send(p);
     firstEncounter = false;
    }

    socket.receive(inData);
    if (inData.getLength() > 0)
    {
        Msg msg;
        try
        {
            msg = Msg.createFromUdp(inData.getData());
            return msg;
        }
        catch (TermMsgException e1)
        {
            return null;
        }
    }
    else
    {
     try
        {
            Thread.sleep(100);
        }
        catch (InterruptedException e)
        {

        }
        return null;
    }
}

Does anyone have a clue? btw... i also use:

DatagramSocket socket;
try {
  socket = new DatagramSocket(50004);
}

Do i have to use server socket to make it listen for more than one datagram package?

Summary: - Port unreachable - Can't receive package number two

Hope someone can help me. Thanks in advance

+1  A: 

The first problem, as already mentioned in the comments on the question, is that you are assuming that the following two lines are two UDP packets being sent.

Package one(from wireshark): "5955 11994.023974 192.168.1.3 192.168.1.2 UDP Source port: 50000 Destination port: 50004"

Package two(from wireshark): 5958 11994.045830 192.168.1.3 192.168.1.2 ICMP Destination unreachable (Port unreachable)

In actual fact, this is probably an incomplete trace, since this is showing two packages:

Package one(from wireshark): "5955 11994.023974 192.168.1.3 192.168.1.2 UDP Source port: 50000 Destination port: 50004"

This is a UDP packet, from server2 (192.168.1.3) to server1 (192.168.1.2). It is being sent to port 50004 on server1.

Package two(from wireshark): 5958 11994.045830 192.168.1.3 192.168.1.2 ICMP Destination unreachable (Port unreachable)

This is a control message being sent from server2 to server1 saying that a previous packet could not be delivered because the destination port was not open. This is an answer from a previous packet delivery attempt from server1 to server2, that did not work. This might help to explain why you are not getting all the packets that you expect?

Paul Wagland
"This is an answer from a previous packet delivery attempt from server1 to server2"- This is what i have been thinking all the time, but i can't understand why it can't reach it's destination.- As i said in another comment, i made a script that sent packages ti Server1, and they reached their target.
It still does show package two from wireshark, but i have now accomplished to receive both packages.Thanks for the brainstorming; kdgregory and Paul Wagland :)
Is there a firewall blocking access to the port?
John Meagher