Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Incoming UDP packet interrupts call flow - how to fix this?

807589Jul 21 2008 — edited Jul 22 2008
First of all, thanks to all who reply to my question.

In my own words here is the problem. I have UDP client which sends and receives UDP packets. There is a controlling list which specifies what client should be doing at any point. For example, the client traverses through the list and the conrolling list says it should send out an UDP packet it does so and updates statistics screen (JTextArea). Then, controlling list says it should receive a packet and it does so. After UDP packet comes in, it again updates the statistics screen (the same JTextArea). Now, the problem I am seeing is that if an incoming UDP packet comes in while the statistics screen is being updated for an outgoing packet, update function is interrupted. This causes me a problem. The question is how do I make sure that incoming UDP packet does not interrupt my (kind of slow executing screen update function) or how should I design my client so I do not have interrupt 'issues'?

Here is the code snippet:
  try
        {
            for (i = 0; i < cnt; i++)
            {
                entry = (MsgJTreeEntry) ((DefaultMutableTreeNode) model.getChild(root, i)).getUserObject();
                if (entry.getMsgTreeEntryDirection() == MsgJTreeEntry.SIP_MSG_DIRECTION.OUT_MSG)
                {
                    sendData = entry.getSipString().getBytes();
                    packet = new DatagramPacket(sendData, sendData.length);
                    ((DatagramSocket) mySocket.getSocket()).send(packet);
                    entry.incExecutedCnt();
                    updateStats(i, entry);      //<--- This is interrupted by incoming UDP packet and it creates me a problem
                }
                else
                {
                    expected = entry.getSipString().substring(0, 3);
                    packet = new DatagramPacket(receiveData, receiveData.length);
                    while (true)
                    {
                        ((DatagramSocket) mySocket.getSocket()).receive(packet);  //<-- If new packet comes in it interrupts updateStats for outgoing packet
                        incomingMsg = new String(packet.getData());
                        if (incomingMsg.indexOf("SIP/2.0") == 0)
                        {
                            received = incomingMsg.substring(8, 11);
                        }
                        else
                        {
                            pos = incomingMsg.indexOf(' ');
                            if (pos == -1)
                            {
                                entry.incUnexpectedCnt();
                                updateStats(i, entry);
                                continue;
                            }
                            received = incomingMsg.substring(0, pos);
                        }
                        if (expected.equals(received) == true)
                        {
                            entry.incExecutedCnt();
                            updateStats(i, entry);
                            break;
                        }
                        else
                        {
                            entry.incUnexpectedCnt();
                            updateStats(i, entry);
                        }
                    }
                }
            }
        }
Edited by: zcoklin on Jul 21, 2008 9:44 AM
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Aug 19 2008
Added on Jul 21 2008
8 comments
589 views