Martina312

Server

Apr 20th, 2020
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.67 KB | None | 0 0
  1. package ispitna;
  2.  
  3. import java.io.IOException;
  4. import java.net.ServerSocket;
  5. import java.net.Socket;
  6.  
  7. public class Server extends Thread {
  8.     ServerSocket serverSocket;
  9.     String path;
  10.  
  11.  
  12.     public Server(int port, String path) throws IOException {
  13.         this.serverSocket = new ServerSocket(port);
  14.         this.path = path;
  15.     }
  16.  
  17.     @Override
  18.     public void run() {
  19.         try {
  20.             while (true) {
  21.                 Socket socket = serverSocket.accept();
  22.                 ServerWorker sw = new ServerWorker(socket, path);
  23.                 sw.start();
  24.             }
  25.         } catch (IOException e) {
  26.             e.printStackTrace();
  27.         }
  28.     }
  29. }
Add Comment
Please, Sign In to add comment