Solved

Socket Deadlock

Posted on 2004-08-19
9
251 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
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...
0
 
LVL 35

Accepted Solution

by:
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?

Regards
0
 

Author Comment

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

0
 
LVL 35

Expert Comment

by:girionis
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.

0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

Author Comment

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

Expert Comment

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

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

Author Comment

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

Expert Comment

by:girionis
ID: 11890286
Thank you for accepting :)
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Java 1603 Error 3 50
eclipse formatting 6 71
eclipse java  build path 6 43
java stored proc example 9 19
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…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
Viewers learn about the “while” loop and how to utilize it correctly in Java. Additionally, viewers begin exploring how to include conditional statements within a while loop and avoid an endless loop. Define While Loop: Basic Example: Explanatio…
The viewer will learn how to implement Singleton Design Pattern in Java.

919 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

18 Experts available now in Live!

Get 1:1 Help Now