Advertisement
fatalryuu

Untitled

May 2nd, 2023
225
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.04 KB | None | 0 0
  1. private Player getPlayer() throws Exception {
  2.  
  3.  
  4. //Infinite loop until successful connection with a socket
  5. while (true) {
  6.  
  7. //Waiting for a socket to connect
  8. s = serverSocket.accept();
  9.  
  10. //Setting timeout for connection reads
  11. s.setSoTimeout(2000);
  12. reader = new BufferedReader(new InputStreamReader(s.getInputStream()));
  13. writer = new PrintWriter(s.getOutputStream(), true);
  14.  
  15. //Waiting 2 seconds for socket to send lobby code
  16. clientCode = reader.readLine();
  17. clientName = reader.readLine();
  18.  
  19. //Making sure lobby code is correct
  20. boolean isUniqueName = true;
  21. if (code.equals(clientCode)) {
  22. writer.println(lobbySize);
  23. writer.println(language);
  24. return new Player(s);
  25. } else {
  26. writer.println("F");
  27. s.close();
  28. }
  29.  
  30. }
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement