Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17


Socket Deadlock

Posted on 2004-08-19
Medium Priority
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
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 150 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.

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

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: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say 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

INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.
Suggested Courses

722 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