aspose file tools*
The moose likes Sockets and Internet Protocols and the fly likes Server and Client  communication probs Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Sockets and Internet Protocols
Bookmark "Server and Client  communication probs" Watch "Server and Client  communication probs" New topic
Author

Server and Client communication probs

Con Lu
Ranch Hand

Joined: Aug 27, 2002
Posts: 38
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

Joined: Aug 27, 2002
Posts: 38
Just to add that the question above is regarding pre-1.4 code.
Thanks
Michael Morris
Ranch Hand

Joined: Jan 30, 2002
Posts: 3451
Have you tried flushing the PrintWriters after each write?


Any intelligent fool can make things bigger, more complex, and more violent. It takes a touch of genius - and a lot of courage - to move in the opposite direction. - Ernst F. Schumacher
Con Lu
Ranch Hand

Joined: Aug 27, 2002
Posts: 38
I have already flushed the PrintWriter. Please see code below:-


// CLIENT CLASS CODE

[ June 13, 2003: Message edited by: Michael Morris ]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Server and Client communication probs