Advertisement
Guest User

ServerTest.java

a guest
Oct 26th, 2011
698
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.95 KB | None | 0 0
  1. import java.io.IOException;
  2. import java.net.ServerSocket;
  3. import java.net.Socket;
  4. import java.util.ArrayList;
  5. import java.util.List;
  6.  
  7. public class ServerTest {
  8.  
  9. private ServerSocket serverSocket;
  10.  
  11. private List<ClientSession> sessions = new ArrayList<ClientSession>();
  12.  
  13. public ServerTest(int port) throws IOException{
  14. serverSocket = new ServerSocket(port);
  15.  
  16. initClientListener();
  17. }
  18.  
  19. private void initClientListener(){
  20. System.out.println("initClientListener()");
  21. Thread t = new Thread(new Runnable() {
  22.  
  23. @Override
  24. public void run() {
  25. while(true){
  26. try {
  27. Socket socket = serverSocket.accept();
  28. ClientSession session = new ClientSession(socket);
  29. sessions.add(session);
  30. } catch (IOException e) {
  31. e.printStackTrace();
  32. }
  33. }
  34. }
  35. });
  36. t.start();
  37. }
  38.  
  39.  
  40. public static void main(String[] args) throws IOException {
  41. ServerTest test = new ServerTest(1234);
  42. }
  43.  
  44. }
  45.  
  46.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement