Advertisement
Guest User

Untitled

a guest
Aug 22nd, 2017
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.82 KB | None | 0 0
  1. private void whileChatting() throws IOException {
  2. sendMessage("&nume"+nume);
  3. do {
  4. try {
  5. Object object = input.readObject();
  6.  
  7. if(object instanceof String)
  8. showMessage("n" + (String) object);
  9.  
  10. //here is where i want to receive objects so that's why i used instanceof
  11.  
  12. } catch (ClassNotFoundException var2) {
  13. showMessage("Unknown data received!");
  14. }
  15. } while(!message.equals("SERVER - END"));
  16. }
  17.  
  18. @Override
  19. public void run() {
  20.  
  21. String message = " ";
  22. try {
  23. Object object = new Object();
  24. while (true){
  25. object = reader.readObject();
  26.  
  27. if(object instanceof String){
  28. message = (String) object;
  29. System.out.println(message);
  30. if(message.startsWith("&nume")) {
  31. nume = message.substring(5);
  32. sendToAll(nume + " connected");
  33. //playersState.addTo(nume , playersState.getLobbyPlayers()); <------------
  34. //here is the problem
  35. }
  36. else if(message.startsWith("/left")){
  37. sock.close();
  38. sendToAll(nume + " left");
  39. break;
  40. }
  41. else sendToAll(nume + " - " +message);
  42. }
  43.  
  44. }
  45.  
  46. } catch (Exception ex) {
  47. try {
  48. System.out.println("inchis");
  49. sock.close();
  50. } catch (IOException e) {
  51. // TODO Auto-generated catch block
  52. System.exit(0);
  53. }
  54. }
  55.  
  56.  
  57. }
  58.  
  59. public void addTo(String name, List<String> list){
  60. list.add(name);
  61. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement