import java.net.*;
import java.io.*;
public class srv_main {
public static void main(String[] args) throws IOException {
ServerSocket ssock = null;
try {
ssock = new ServerSocket(4456);
} catch (IOException e) {
e.printStackTrace();
System.err.println("[ERROR]: Could not listen on port 4456. Other server running?");
System.exit(-1);
}
System.out.println("[SERVER]: Server started on port: 4456");
Socket sock = null;
try {
sock = ssock.accept();
} catch (IOException e1) {
System.err.println("[ERROR]: Accept failed.");
System.exit(-1);
}
System.out.println("[SERVER]: Client connected");
PrintWriter out = new PrintWriter(sock.getOutputStream(), true);
BufferedReader in = new BufferedReader(new InputStreamReader(sock.getInputStream()));
String input;
while((input = in.readLine()) != null) {
System.out.println("[SERVER]: From Client: " + input);
if ("bye".equals(input)) {
out.println("Bye bye <3");
break;
} else {
out.println(input+": From server <3");
}
}
System.out.println("[SERVER]: Shutting Down");
out.close();
in.close();
sock.close();
ssock.close();
System.out.println("[SERVER]: Shutdown Complete");
}
}