I am programming a server in Java with org.apache.sshd library. For this, I want to send an easy login to the client. After that, the client should be able to send a text message to the server. The message should be stored somehow. The problem, which I am facing at the moment is as follows: I can login onto the server. My "Welcome to the Server" message is shown on the client side. After that it's not possible to write any text in the line (if so it is not shown) and send it to the server.
My serverStart method, which is used in the main of course.
public void serverStart() throws IOException {
SshServer sshd = SshServer.setUpDefaultServer();
sshd.setPort(22);
sshd.setKeyPairProvider(new SimpleGeneratorHostKeyProvider());
sshd.setPasswordAuthenticator(new PasswordAuthenticator());
sshd.setShellFactory(channel -> new ExampleShell());
sshd.start();
}
PasswordAuthenticator
public class PasswordAuthenticator implements org.apache.sshd.server.auth.password.PasswordAuthenticator {
public PasswordAuthenticator() {
users.put("admin", "admin");
}
private void addUserAndPassword(String username, String password) {
users.put(username, password);
}
@Override
public boolean authenticate(String username, String password, ServerSession session) {
String storedPassword = users.get(username);
return storedPassword != null && storedPassword.equals(password);
}
}
Here the start method of my ExampleShell():
@Override
public void start(ChannelSession channel, Environment env) throws IOException {
BufferedReader reader = new BufferedReader(new InputStreamReader(in));
PrintWriter writer = new PrintWriter(out, true);
out.write("Login successful. Welcome!\r\n".getBytes(StandardCharsets.UTF_8));
out.flush();
String inputLine;
while ((inputLine = reader.readLine()) != null) {
System.out.println("Received: " + inputLine);
out.write(("You typed: " + inputLine + "\r\n").getBytes(StandardCharsets.UTF_8));
out.flush();
}
}
I tried with BufferedReader and reader.readLine(), as I understand I should be able to type a message and send it hitting enter but nothing works here.