• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 330
  • Last Modified:

dockets and readLine()

if DataInputStream.readLine block until char(13) , and i"m using sockets for communiction so if client and server coming both to readline(), then all the proccess stack , right?
for some reasone my comunication between the client and the server get stuck after a few msg dialog ,any other idea ?
how can i solv it ?
10x in advance
  • 3
  • 2
1 Solution
asiAuthor Commented:
does a communication with sockets and stream inforce order between the client and the server (i.e :one sentence server and one client ) ?
asiAuthor Commented:
if the answer to the last comment is yes ? what is the oaltrnative to un order connection ?
Can you explain what you are doing a bit more....

I assume you communication protocol is failing..?

If you are writing a clinet/server app both the client and the server must know what data to expect.. (protocol)

For example.. if you send 2 strings to the client (from the server) the client must know how many string to retrieve..


client reads how many and expects that many..

for(int i=0;i<how_many;i++)

string1 = dis.readUTF();
string1 = dis.readUTF();
string_n = dis.readUTF();


I'm not sure what your problem is though.. can u explain it som more..

Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

You have to define your custom message system. In the most simple case it should be something like this:

//Control line
Line1 : "DO X, DATA N"
Next N lines contain data

When the server (or the client) receives a control line, it knows what to read afterwards. Also, it is good the communication to be, from the type,
request, response, request, response,....

so, it won't hapen bot the server and the client to wait for a request (or responce) simultaneously, which case they'll both block.

Another solution. Make two channels, outgoing and incomming, preferably in separate threads. this way you will be able to send , while waiting and receive while sending. this is especially valid for the server.

asiAuthor Commented:
change your statuse to answer
and i'll give u the pointe
(i find some other solution , every time client or server receive somthing he should send immeditli "ping " one direction msg (in case that there is nothing else in the outgoing line
but u desever the points   ...

sure. you're welcome.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

The 14th Annual Expert Award Winners

The results are in! Meet the top members of our 2017 Expert Awards. Congratulations to all who qualified!

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now