VersionedConnection getConnection() throws IOException { sendVersionHeader(); IoFuture<Void> futureWelcome = WelcomeMessageReceiver.awaitWelcomeMessage(channel); IoFuture.Status result = futureWelcome.await(timeoutSeconds, TimeUnit.SECONDS); switch (result) { case DONE: // Set this first as something will need to start handling the response messages. channel.receiveMessage(new MessageReceiver()); break; case FAILED: throw futureWelcome.getException(); default: throw new IOException("Unable to obtain connectionId, status=" + result.toString()); } sendKeyPairs(); String connectionId = begin(); ClientConnection cc = new ClientConnection(channel, environment, clientRequestManager, clientExecutorManager, connectionId); cc.start(); return cc; }
Socket s = serverSocket.accept(); ClientConnection temp = new ClientConnection(s); //Changed this line connectedClients.add(temp); System.out.println("Client connection caught and initialized. Client: " + s); System.out.println("Connection with " + s + " now listening for incoming packets."); ThreadAction(temp); CleanClientList();
// Somewhat pseudo-code... Server server = new Server(); server.onStartedListening(new Runnable() { @Override public void run() { executor.execute(new ClientConnection()); } }); executor.execute(server);
class ClientConnection{ private static ClientConnection conn = null; Socket mSocket; // your socket protected ClientConnection(){ mSocket = new Socket(); // mSocket.connect( bla bla bla ) } public Socket getSocket(){ return mSocket(); } public static ClientConnection getInstance(){ if(conn == null){ synchronized (LOCK) { if(conn == null){ conn = new ClientConnection(); } } } return conn; } }
while (true) { // respond to clients Socket receiverSocket = serverSocket.accept(); System.out.println("receiver client connected!"); Socket senderSocket = serverSocket.accept(); System.out.println("sender client connected!"); ClientConnection connection = new ClientConnection(senderSocket, receiverSocket); Thread connectionThread = new Thread(connection); connectionThread.start(); }
while((clientSocket = serverSocket.accept()) != null){ System.out.println("got client from"+clientSocket.getInetAddress()); ClientConnection clientConnection = new ClientConnection(clientSocket); clientConnectionList.add(clientConnection); ClientHandler clientHandler = new ClientHandler(clientConnection,serverSocket);
ClientConnection connection = new ClientConnection(this, socket);
VersionedConnection getConnection() throws IOException { sendVersionHeader(); IoFuture<Void> futureWelcome = WelcomeMessageReceiver.awaitWelcomeMessage(channel); IoFuture.Status result = futureWelcome.await(timeoutSeconds, TimeUnit.SECONDS); switch (result) { case DONE: // Set this first as something will need to start handling the response messages. channel.receiveMessage(new MessageReceiver()); break; case FAILED: throw futureWelcome.getException(); default: throw new IOException("Unable to obtain connectionId, status=" + result.toString()); } sendKeyPairs(); String connectionId = begin(); ClientConnection cc = new ClientConnection(channel, environment, clientRequestManager, clientExecutorManager, connectionId); cc.start(); return cc; }
VersionedConnection getConnection() throws IOException { sendVersionHeader(); IoFuture<Void> futureWelcome = WelcomeMessageReceiver.awaitWelcomeMessage(channel); IoFuture.Status result = futureWelcome.await(timeoutSeconds, TimeUnit.SECONDS); switch (result) { case DONE: // Set this first as something will need to start handling the response messages. channel.receiveMessage(new MessageReceiver()); break; case FAILED: throw futureWelcome.getException(); default: throw new IOException("Unable to obtain connectionId, status=" + result.toString()); } sendKeyPairs(); String connectionId = begin(); ClientConnection cc = new ClientConnection(channel, environment, clientRequestManager, clientExecutorManager, connectionId); cc.start(); return cc; }