Advertisement
Guest User

Untitled

a guest
May 20th, 2018
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.30 KB | None | 0 0
  1. // LINK LABORATOR: bit.ly/2JLqfpl
  2.  
  3. package laborator10;
  4.  
  5. import java.io.IOException;
  6. import java.io.ObjectInputStream;
  7. import java.io.ObjectOutputStream;
  8. import java.net.InetAddress;
  9. import java.net.ServerSocket;
  10. import java.net.Socket;
  11. import java.net.UnknownHostException;
  12. import java.util.LinkedList;
  13. import java.util.List;
  14.  
  15. public class Laborator10 {
  16. public static int numar;
  17. public static List<Mesaj> mesaje = new LinkedList();
  18.  
  19. public static void main(String[] args) throws UnknownHostException, IOException, ClassNotFoundException {
  20.  
  21. // Runnable run = new Runnable() {
  22. // public void run() {
  23. // for(int i=0; i<1000; i++) {
  24. // synchronized(Laborator10.class) {
  25. // numar++;
  26. // }
  27. // }
  28. // System.out.println(numar);
  29. // }
  30. // };
  31. //
  32. // for(int i=0; i<20; i++) {
  33. // Thread thread = new Thread(run);
  34. // thread.start();
  35. // }
  36.  
  37.  
  38. ServerSocket ss = new ServerSocket(12345, 1000, InetAddress.getByName("127.0.0.1"));
  39. Socket socket = ss.accept();
  40.  
  41. ObjectOutputStream o = new ObjectOutputStream(socket.getOutputStream());
  42. for(Mesaj m:mesaje) {
  43. o.writeObject(m);
  44. }
  45.  
  46. ObjectInputStream i = new ObjectInputStream(socket.getInputStream());
  47. while(true) {
  48. Mesaj m = (Mesaj) i.readObject();
  49. mesaje.add(m);
  50. }
  51. }
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement