I created a really simple Java program that creates a java.net.ServerSocket on an open port, x, and waits for a connection using accept (). I want to use telnet/ssh to connect to the program via port x so that I can communicate with said program. My problem is after I connect to the port, my program recognizes and accepts the connection, but ssh freezes. I’m assuming this is because I don’t have the proper response. I just wanna know what I should be doing next. How do I respond?
I could use a library, but I’d like to understand what should come next. However, I would still really appreciate someone telling me if I really should be using a library. Also, I know some basic networking concepts like TCP/IP, OSI, and that data gets wrapped, sent, then unwrapped, but that’s the extent of my networking knowledge.
sshis probably much too complicated for what you want to achieve. It freezes because it waits for a response from your server that it probably never gets.sshhas also complicated security requirements that you probably don’t want to implement for your simple server.Why don’t you start with something very basic on the client side as in this tutorial. From there on, you can still add features and functionality as needed.
Edit:
Sending commands with telnet:
Client Side:
Just issue
telnet host port, there you typesay Hello Worldand hit Enter.Server side:
You receive a stream of bytes from your client. First you have to parse it as a String. Then you could simply split this String by looking for the first whitespace character. The string before that is your ‘command’, the part after the whitespace is your ‘payload’.
In the example this would give you ‘say’ as the command and ‘Hello World’ as the payload.
Then compare the ‘command’ with a list of known commands, and based on what command you have you can then execute it with the payload as an argument.