Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // LINK LABORATOR: bit.ly/2JLqfpl
- package laborator10;
- import java.io.IOException;
- import java.io.ObjectInputStream;
- import java.io.ObjectOutputStream;
- import java.net.InetAddress;
- import java.net.ServerSocket;
- import java.net.Socket;
- import java.net.UnknownHostException;
- import java.util.LinkedList;
- import java.util.List;
- public class Laborator10 {
- public static int numar;
- public static List<Mesaj> mesaje = new LinkedList();
- public static void main(String[] args) throws UnknownHostException, IOException, ClassNotFoundException {
- // Runnable run = new Runnable() {
- // public void run() {
- // for(int i=0; i<1000; i++) {
- // synchronized(Laborator10.class) {
- // numar++;
- // }
- // }
- // System.out.println(numar);
- // }
- // };
- //
- // for(int i=0; i<20; i++) {
- // Thread thread = new Thread(run);
- // thread.start();
- // }
- ServerSocket ss = new ServerSocket(12345, 1000, InetAddress.getByName("127.0.0.1"));
- Socket socket = ss.accept();
- ObjectOutputStream o = new ObjectOutputStream(socket.getOutputStream());
- for(Mesaj m:mesaje) {
- o.writeObject(m);
- }
- ObjectInputStream i = new ObjectInputStream(socket.getInputStream());
- while(true) {
- Mesaj m = (Mesaj) i.readObject();
- mesaje.add(m);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement