You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@mina.apache.org by ramesh murugaswamy <ra...@rediffmail.com> on 2007/01/29 15:36:20 UTC

An existing connection was forcibly closed by the remote host

  
Hi, 

I try to connect to chat server(From Chat Example)  with client socket code.I got the Exception "An existing connection was forcibly closed by the remote host".but i connected through  putty, it is wotking fine.Actually What is the problem.My Client Code is


public static void main(String[] args) {
	 String host = "localhost";
	 Socket	connection = null;   
     try {
		 connection = new Socket(host, 1234);
		 connection.setKeepAlive(true);
		 connection.setSoLinger(true,10);
		 System.out.println("SocketConnected");
		 //Writer out = new OutputStreamWriter(connection.getOutputStream( ), "8859_1");
			String str = "Ramesh";
         while(connection.isConnected())
		 {
			System.out.println("--- isConnected ---> " + connection.isConnected());
			DataOutputStream out = new DataOutputStream(connection.getOutputStream());
			System.out.println("***");
			out.write(str.getBytes(), 0, str.length());
			out.flush();
			out.close();
			Thread.sleep(1000);
		 }
  	}catch (UnknownHostException ex) {
        System.err.println(ex);
        //break;
     }

     catch (Exception ex) {
		System.err.println(ex);
      // must not be a server on this port
     }

regds
Ramesh.M
    

RE: An existing connection was forcibly closed by the remote host

Posted by "Newcomb, Michael-P57487" <Mi...@gdc4s.com>.
> DataOutputStream out = new
DataOutputStream(connection.getOutputStream());
> System.out.println("***");
> out.write(str.getBytes(), 0, str.length());
> out.flush();
> out.close();
  ^^^^^^^^^^^

Not sure if I read your e-mail correctly, but 'out.close()' will close
the socket's OutputStream which closes the socket.

Michael