Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.IOException;
- import java.net.ServerSocket;
- import java.net.Socket;
- import java.util.ArrayList;
- import java.util.List;
- public class ServerTest {
- private ServerSocket serverSocket;
- private List<ClientSession> sessions = new ArrayList<ClientSession>();
- public ServerTest(int port) throws IOException{
- serverSocket = new ServerSocket(port);
- initClientListener();
- }
- private void initClientListener(){
- System.out.println("initClientListener()");
- Thread t = new Thread(new Runnable() {
- @Override
- public void run() {
- while(true){
- try {
- Socket socket = serverSocket.accept();
- ClientSession session = new ClientSession(socket);
- sessions.add(session);
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
- }
- });
- t.start();
- }
- public static void main(String[] args) throws IOException {
- ServerTest test = new ServerTest(1234);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement