So, right now, the only thing I've managed to do, is, on connect, pw.printin("Hi")
. Now the receiving side of the client may reply with "Hello", and if it does, I want to answer with "Hi" , and then have it reply with "Hello" again, in an endless loop that only gets interrupted in another if statement.
try {
ServerSocket serverSocket = new ServerSocket(90);
while(true) {
String str= "Hello";
Socket socket = serverSocket.accept();
OutputStream os = socket.getOutputStream();
PrintWriter pw = new PrintWriter(os, true);
BufferedReader br = new BufferedReader(new InputStreamReader(socket.getInputStream()));
pw.println("Hi");
if(br.readLine().equals(str)){
pw.println("Hi");
}
System.out.println(str);
}
} catch (IOException e) {
try {
if(serverSocket!= null){
serverSocket.close();
}
}
catch (IOException e1){
e1.printStackTrace(System.err);
}
}
return 500;
}
}