Socket Deadlock

Posted on 2004-08-19
Last Modified: 2008-03-06

I have a client server Java application. The client must synchronise data with the server and then close a connection.

Here is a brief summary of the steps :

The client connects to the server socket app and send a START string. The server responds with a READY string. The client then sends it's data to the server . The server will call  readUTF() until the client sends data which includes a special terminating character. the problem is the data with the terminating character in it may get lost and never reach the server. As a result the server is waiting forever, deadlocked. the client too cannot proceed until it has a response from the server.  The client too may become locked if the server's READY string never reaches it.
At the moment I am developing on our LAN and communication is fine, no packets get lost and it all works fine, but the final version is over GPRS and I'm concerned that packets will get lost.

Could someone advice as to how to prevent should deadlock occuring ?


Question by:kfc23
  • 4
  • 3
LVL 35

Expert Comment

ID: 11843199
send "AGAIN" messages from the server if it doesn't get a proper response within a specified timeframe?

The clien upon recieving an "AGAIN" message will send the last data it sent again...

That should do it...
LVL 35

Accepted Solution

girionis earned 50 total points
ID: 11843200
Hi kfc23,

If you keep using sockets this will guarantee that packets will arrive and arrive in the order they are sent. I wouldn't worry that much since TCP/IP is an excellent protocol to guarantee data delivery.

What protocol does GPRS use to transfer data?


Author Comment

ID: 11845350
not too sure what protocol GPRS uses. i don't think it's as reliable as TCP/IP though.

When creating a socket you can specify a timeout value, which causes the socket to throw an exception when it can't read . I could use this to issue an AGAIN command to the client. Not sure about the client side though. I'm using IMP which is a scaled down version of J2ME. You can't create sockets in the manner you would for a J2SE app so I'm not sure about using the timeout for the client side.

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

LVL 35

Expert Comment

ID: 11849741
You can always wait for a response and if you do not get it resent the data. Have a separate thread that does this.


Author Comment

ID: 11889812
finally got to test over GPRS and the code is stable enough. it seems that GPRS is stable once it establishes an initial connection.
LVL 35

Expert Comment

ID: 11889895
Nice :)

If any of the comments above helped you please accept an answer/split points, otherwise ask a question to community support for zero points to PAQ & refund the points:

Author Comment

ID: 11890274
my only issue now is that  at times it takes up to a minute to connect to our server over GPRS.  depends on the time of the day etc. but thankfully that's not my problem :-) . thanks for the help .
LVL 35

Expert Comment

ID: 11890286
Thank you for accepting :)

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Tomcat: Unable to run tomcat service. 2 24
null output 3 35
Eclipse Java import and method not resolved 4 50
swing controls 2 16
Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.

828 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question