The Artima Developer Community
Sponsored Link

Legacy Java Answers Forum
December 2001



This page contains an archived post to the Java Answers Forum made prior to February 25, 2002. If you wish to participate in discussions, please visit the new Artima Forums.


This might help

Posted by Hiran on December 07, 2001 at 3:48 PM

Try this link:
Writing the server side of a socket
Sun creates a simple Knock Knock program to demonstrate server side programming. (There is even a link to supporting multiple clients). From what I can gather, a PrintWriter is created from using the socket's getOutputStream method, and a BufferedReader is created using the socket's getInputStream method. A while loop is used to check to see if the BufferedReader object's readLine method is null, and while it isn't the input is processed (using the KnockKnockProtocol Sun created) and the response(s) are written using the PrintWriter object. Your scenario would be similar, except in the while loop the file will be sent using the PrintWriter object (or whatever class you're using). Hope this helps.

> i am trying to send a file over a socket connection.
> a server gets a request and socket connection is established.
> so far so good.
> now i want to open streams on the server side, but it i need both input streams and output streams. input to read request type from client and output to write the file to client.
> it goes like this: first, server reads request from inputstream. second, server sends file. third, server (tries to) read from inputstream again, to see if there are additional requests or end of request code.
> my problem is on the third step, the server wont read anything more at this point it seems, it just blocks, why? I am sending more data from the client, so its not that.
> Id be very gratefull for tips on this. Thanks.
> /sebastian


Sponsored Links

Copyright © 1996-2009 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use - Advertise with Us