Esempio 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);
 }
Esempio 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);
     }
   }
 }
 /**
  * Takes the input transmitted by a client and creates or updates the local instances that
  * represent the objects on the client.
  *
  * @param ec the container with the client's objects
  */
 public void setOrUpdate(ExtendedDataContainer ec) {
   ClientInfo ci = ec.getClientInfo();
   LocalObjectList lol = getLocalObjectList(ci);
   LocalObject lo = new LocalObject(ci.getID(), true);
   ec.fillLocalObject(lo);
   boolean found = false;
   for (Iterator<LocalObject> itty = lol.iterator(); itty.hasNext(); ) {
     LocalObject lot = itty.next();
     if (lot.equals(lo)) {
       lot.copyFrom(lo);
       found = true;
       break;
     }
   }
   if (!found) {
     lol.add(lo);
     NetLogger.log(
         "Server: Added an object of client "
             + ci.getID()
             + "! Client's object count is now: "
             + lol.size());
   }
 }
 /**
  * Removes an object from the server's list, i.e. it doesn't exist on the client any longer.
  *
  * @param lo the object to remove
  * @param ci the client info
  */
 public void removeObject(LocalObject lo, ClientInfo ci) {
   LocalObjectList lol = getLocalObjectList(ci);
   boolean ok = lol.remove(lo);
   if (ok) {
     NetLogger.log(
         "Server: Removed an object ("
             + lo.getObjectID()
             + ") of client "
             + ci.getID()
             + "! Client's object count is now: "
             + lol.size());
   } else {
     NetLogger.log("Server: Failed to remove object of client " + ci);
   }
 }