Advertisement
Guest User

edvisLavonas.java

a guest
Nov 30th, 2015
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.54 KB | None | 0 0
  1. /*
  2. * To change this license header, choose License Headers in Project Properties.
  3. * To change this template file, choose Tools | Templates
  4. * and open the template in the editor.
  5. */
  6. package serveris;
  7.  
  8. import java.net.ServerSocket;
  9. import java.net.Socket;
  10. import java.util.ArrayList;
  11.  
  12. /**
  13. *
  14. * @author Justas
  15. */
  16. public class Serveris {
  17.  
  18. public static void main(String[] a){
  19.  
  20. ServerSocket serverSocket = null;
  21. //sarasas kuriame saugoma info apie vartotojus
  22. ArrayList<User> klientai = new ArrayList();
  23. int counter = 1;
  24.  
  25. try{
  26. //sukuriam serversocket objekta
  27. serverSocket = new ServerSocket(1234);
  28. boolean testi = true;
  29. while(testi){
  30.  
  31. Socket clientSocket = serverSocket.accept();
  32. System.out.println("sulauke naujo kliento" + clientSocket.getInetAddress().getHostAddress());
  33. String nikas = "Klientas_"+counter++;
  34. User klientas = new User(clientSocket,klientai,nikas);
  35. klientas.out.println("nick"+nikas);
  36.  
  37. for(User u : klientai){
  38.  
  39. u.out.println("in"+ nikas);
  40. klientas.out.println("in"+u.nick);
  41. }
  42. klientai.add(klientas);
  43. klientas.start();
  44.  
  45. }
  46. } catch (Exception e){
  47. try{
  48. serverSocket.close();
  49. }catch (Exception ex){
  50.  
  51. }
  52. System.exit(1);
  53. }
  54.  
  55.  
  56. }
  57.  
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement