|
|
|
@ -11,28 +11,28 @@ import java.util.Queue;
@@ -11,28 +11,28 @@ import java.util.Queue;
|
|
|
|
|
* Подключения ставятся в очередь |
|
|
|
|
*/ |
|
|
|
|
public class ServerLauncher implements Runnable{ |
|
|
|
|
private int tcpPort = 8081; |
|
|
|
|
private int port = 8081; |
|
|
|
|
private ServerSocketChannel channel = null; |
|
|
|
|
private Queue<Connection> connectionQueue = null; |
|
|
|
|
private boolean isActive = false;//флаг проверки, запущен ли сервер
|
|
|
|
|
|
|
|
|
|
ServerLauncher(int port, Queue<Connection> connectionQueue){ |
|
|
|
|
tcpPort = port; |
|
|
|
|
this.port = port; |
|
|
|
|
this.connectionQueue = connectionQueue; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public void run() { |
|
|
|
|
try{ |
|
|
|
|
this.channel = ServerSocketChannel.open(); |
|
|
|
|
this.channel.bind(new InetSocketAddress(tcpPort)); |
|
|
|
|
channel = ServerSocketChannel.open(); |
|
|
|
|
channel.bind(new InetSocketAddress(port)); |
|
|
|
|
} catch(IOException e){ |
|
|
|
|
e.printStackTrace(); |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
while(true){ |
|
|
|
|
try{ |
|
|
|
|
SocketChannel accepted = this.channel.accept(); |
|
|
|
|
SocketChannel accepted = channel.accept(); |
|
|
|
|
System.out.println("Socket accepted: " + accepted); |
|
|
|
|
//todo check if the queue can even accept more sockets.
|
|
|
|
|
this.connectionQueue.add(new Connection(accepted)); |
|
|
|
|