Guest User

Untitled

a guest
Jan 16th, 2018
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.81 KB | None | 0 0
  1. public void runServer() {
  2. int port = 3000;
  3. try {
  4. ServerSocket ss = new ServerSocket(port);
  5. System.out.println("Waiting for a client...");
  6.  
  7. Socket socket = ss.accept();
  8. System.out.println("Got a client! " + socket.getInetAddress().getHostAddress());
  9.  
  10. DataInputStream in = new DataInputStream(socket.getInputStream());
  11. DataOutputStream out = new DataOutputStream(socket.getOutputStream());
  12.  
  13. String line = null;
  14. while(true) {
  15. line = in.readUTF();
  16. System.out.println("Input line : " + line);
  17. System.out.print("Sending back... ");
  18. out.writeUTF(line);
  19. out.flush();
  20. System.out.println("Done!");
  21. }
  22. } catch(Exception x) {
  23. System.out.print("Lost Connected");
  24. }
  25. }
Add Comment
Please, Sign In to add comment