0

I was executing a socket program.The program is to, just echo the user input , by the server .ie if the user gives input as Apple the server reply should be Apple. But the problem now i am facing is, the server is sending a message(instead of Apple ) which used to be the Banner Message that we get when we login to the server.Once the banner message is over ,the following error gets displayed :

Exception in thread "main" java.net.SocketException: Software caused connection abort: recv failed
 at java.net.SocketInputStream.socketRead0(Native Method)
 at java.net.SocketInputStream.read(Unknown Source)
 at sun.nio.cs.StreamDecoder.readBytes(Unknown Source)
 at sun.nio.cs.StreamDecoder.implRead(Unknown Source)
 at sun.nio.cs.StreamDecoder.read(Unknown Source)
 at java.io.InputStreamReader.read(Unknown Source)
 at java.io.BufferedReader.fill(Unknown Source)
 at java.io.BufferedReader.readLine(Unknown Source)
 at java.io.BufferedReader.readLine(Unknown Source)
 at EchoClient.main(EchoClient.java:69)

Following is my code :

import java.net.*;
import java.io.*;
public class EchoClient
{
    public static void main(String[] args) throws IOException
    {
        Socket echosocket = null;   
        PrintWriter out =null;
        BufferedReader in=null;

        //establish the socket connection between the client and the server
        // open a PrintWriter and a BufferedReader on the socket: 

        try
        {   
            echosocket = new Socket("ltesol1.comm.mot.com",22);
            out=new PrintWriter(echosocket.getOutputStream(),true);    
            in=new BufferedReader(new InputStreamReader(echosocket.getInputStream()));    

        }
        catch(UnknownHostException e) 
        {
            System.err.print("Unable to find the host dkc678-01");
            System.exit(1);
        }
        catch(IOException e)
        {
            System.err.print("No IO for host dkc678-01");
            System.exit(1);
        }

        BufferedReader stdIn=new BufferedReader(new InputStreamReader(System.in));

        String userInput;

        while((userInput =stdIn.readLine())!= null )
        {
            out.println(userInput);      
            System.out.println("echo :" + in.readLine());  
        }

        out.close();
        in.close();
        stdIn.close();
        echosocket.close();
    }   

}
8
  • 1
    Please format your code/message, use the 101010 button for code. Thank you. Commented Nov 25, 2010 at 8:40
  • 1
    Make some effort to reduce the code to a minimal program that exhibits the fault. You currently have a bunch of irrelevant stuff mixed in. Commented Nov 25, 2010 at 8:48
  • 1
    Please stop de-formatting the post with every edit. Commented Nov 25, 2010 at 8:49
  • 1
    Given the current code-example, I'd think the 'problem' could well be at the server. The client fails because something goes wrong with the connecting, making in.readLine() fail. PS: Wait, could it be that sshd is running at the server? Commented Nov 25, 2010 at 8:59
  • Why is this a community wiki? Commented Nov 25, 2010 at 9:02

3 Answers 3

2

If you want too connect to a SSH-Server, you have to use the ssh-protocol: http://javassh.org

You should find the sources of a ssh-client there.

Sign up to request clarification or add additional context in comments.

Comments

0

Can you please comment on my suggestion that another service (ie sshd/telnet server) is listening to port 22 on the server side? Or otherwise give us the server code?

2 Comments

You are right Jochem....Its an SSH connection....you mean i need to change the port ...?then which one could the port be ?
Well, the default echo port is port 7, maybe that's what you expect to be using. Otherwise, your client should connect to the SAME port as your server-application is listening on (if you actually have one)
0

Port 22 is usually used for ssh which is an encrypted connection. You can't use a plain text stream.

In either case, the server is disconnecting the connection. You need to find out why it is doing that.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.