NetworkUser.java 795 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. package server;
  2. import java.io.IOException;
  3. import java.io.InputStream;
  4. import java.io.OutputStream;
  5. import java.net.Socket;
  6. public class NetworkUser {
  7. private String name;
  8. private Socket client;
  9. private InputStream input;
  10. private OutputStream output;
  11. public NetworkUser(String username, Socket client){
  12. this.name = username;
  13. this.client = client;
  14. try {
  15. input = client.getInputStream();
  16. output = client.getOutputStream();
  17. } catch (IOException e) {
  18. System.err.println("Somethings nasty happends with a user");
  19. }
  20. }
  21. /* GETTERS AND SETTERS */
  22. /**
  23. * @return the name of the user
  24. */
  25. public String getName() {
  26. return name;
  27. }
  28. public boolean checkConnection(){
  29. try {
  30. output.write(0);
  31. } catch (IOException e) {
  32. return false;
  33. }
  34. return true;
  35. }
  36. }