Solved

Socket Deadlock

Posted on 2004-08-19
9
250 Views
Last Modified: 2008-03-06
Hello,

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 ?

thanks,

Ken
0
Comment
Question by:kfc23
  • 4
  • 3
9 Comments
 
LVL 35

Expert Comment

by:TimYates
Comment Utility
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...
0
 
LVL 35

Accepted Solution

by:
girionis earned 50 total points
Comment Utility
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?

Regards
0
 

Author Comment

by:kfc23
Comment Utility
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.

0
 
LVL 35

Expert Comment

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

0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 

Author Comment

by:kfc23
Comment Utility
finally got to test over GPRS and the code is stable enough. it seems that GPRS is stable once it establishes an initial connection.
0
 
LVL 35

Expert Comment

by:girionis
Comment Utility
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:

http://www.experts-exchange.com/Community_Support/
0
 

Author Comment

by:kfc23
Comment Utility
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 .
0
 
LVL 35

Expert Comment

by:girionis
Comment Utility
Thank you for accepting :)
0

Featured Post

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Suggested Solutions

Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…

771 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now