Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Server and Client communication probs

 
Con Lu
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
1)I have written a SocketServer on one machine which
a.Waits for a connection from a client
b.Sends a message to the client using a PrintWriter
c.Receives a message from the client using a BufferedReader
2)On another machine I have a client program which
a.Creates a connection with the server
b.Receives the message from the server using a BufferedReader
c.Sends a message to the server using a PrintWriter
My intention was for the tasks executed in the following order:-
1a,2a,1b,2b,2c,1c
Instead, when run the following happens
1a,2a
And then the client stalls (blocking I think).
The following scenarios were tried to ascertain the problem (but to no avail)
A)If I keep the server code the same but comment out step 2b from the client code, the following happens (with 1b, 2b missing)
1a,2a,2c,1c
B) If I keep the server code the same but comment out step 2a from the client code the following happens (with 1c, 2c missing)
1a,2a,1b,2b
C)Keeping the client code the same but comment out step 1b from the server code only following occurs, (with 1b, 1c, 2b, 2c missing)
1a,2a
D)Keeping the client code the same but commenting out step 1c from server results in 1c missing ie
1a,2a,1b,2b,2c

What is the problem? It seems like there is blocking going on somewhere. Is it not possible for a server and client to communicate backwards and forwards?
If necessary, please mention and I will post the code.
Thanks in advance,
 
Con Lu
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Just to add that the question above is regarding pre-1.4 code.
Thanks
 
Michael Morris
Ranch Hand
Posts: 3451
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Have you tried flushing the PrintWriters after each write?
 
Con Lu
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have already flushed the PrintWriter. Please see code below:-


// CLIENT CLASS CODE

[ June 13, 2003: Message edited by: Michael Morris ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic