File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Sockets and Internet Protocols and the fly likes Socket  chat problem 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 "Socket  chat problem" Watch "Socket  chat problem" New topic

Socket chat problem

Pierre Dubeau

Joined: Feb 19, 2001
Posts: 7
I develop a java application to transfer local file to a server (upload).
Here`s the steps that I followed (pseudo-code):
client side
I send the login information (information)

socket = new Socket ("server", port);
fluxOut = socket.getOutputStream();
pw = new PrintWriter(flux, true);

the server reads the login
and return true or false to the client
ServerSocket server = new ServerSocket (port);
socket = server.accept();

fluxin = socket.getInputStream ();
OutputStream fluxOut = socket.getOutputStream();
pw = new PrintWriter(fluxOut, true);

the client receive from the server (true or false)
InputStream fluxIn = socket.getInputStream ();
BufferedReader br = new BufferedReader(new InputStreamReader(fluxIn));
if the login is valid the client send the file to the server
I open a new socket
socket1 = new Socket("server", port);
fluxOut = socket1.getOutputStream();
InputStream fluxIn = new FileInputStream(file);
the server receive the file
fluxIn = socket.getInputStream()
while ( ( cnt = != -1)
adler32.update(buffer, 0, cnt);
fluxOut.write(buffer, 0, cnt);
When I tried to open an socketOutputStream on the server
and an SocketInputStream on the client, nothing happends!!
when I use System.out.println(socket.toSting() ) it'ok
I got no error such as Socket closed.
Is there a limit of opening new streams to the same socket?

Any clue!!
Thanks for any help.
I agree. Here's the link:
subject: Socket chat problem
It's not a secret anymore!