• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Socket chat problem

 
Pierre Dubeau
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi
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);
pw.println(information);

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

}
fluxin = socket.getInputStream ();
OutputStream fluxOut = socket.getOutputStream();
pw = new PrintWriter(fluxOut, true);
pw.println("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 = fluxIn.read(buffer)) != -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.
Pierre
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic