Ejemplo n.º 1
0
 protected void registeredClient(SocketChannel sc) throws IOException {
   ClientInfo ci = new ClientInfo();
   ci.channel = sc;
   ci.outBuf.clear();
   ci.outBuf.put(TypeServerConstants.WELCOME);
   ci.outBuf.flip();
   allClients.put(sc, ci);
   send(sc, ci);
 }
Ejemplo n.º 2
0
 private void send(SocketChannel sc, ClientInfo ci) throws IOException {
   int len = ci.outBuf.remaining();
   int nBytes = sc.write(ci.outBuf);
   if (nBytes != len) {
     // Client not ready to receive data
     ci.outputPending = true;
     ci.channel.register(selector, SelectionKey.OP_READ | SelectionKey.OP_WRITE);
   } else {
     ci.outBuf.clear();
     if (ci.outputPending) {
       ci.outputPending = false;
       ci.channel.register(selector, SelectionKey.OP_READ);
     }
   }
 }