1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
| public class ServerConnection {
var client: Client;
var socket: Socket;
var protocol: ClientToServerProtocol;
public function openConnection(address: String, client: ClientTest) {
this.client = client;
socket = new Socket(address, PORT);
protocol = ClientToServerProtocol {};
protocol.initProtocol(socket);
println("[Server Connection] Socket Opened");
def pool : ExecutorService = Executors.newCachedThreadPool();
var task: Runnable = Runnable {
override function run() {
while(socket.isConnected()) {
protocol.processRequest(client);
FX.deferAction(function() {
[....]
});
}
}
}
pool.execute(task);
}
} |