Esempio n. 1
0
  // CONCURRENCIA rebre i enviar
  // Aquests dos métodes utilitzen recursos compartits, els buffers d'enviament
  // i recepció, per tant els synchronitzem.
  public synchronized void rebre(SelectionKey clau) throws IOException {
    SocketChannel s = ((SocketChannel) clau.channel());
    int userId = arraySocketChannels.indexOf(s);
    bbReceptor.clear();
    s.read(bbReceptor);
    bbReceptor.flip();

    // Comprovem que hagi rebut un Integer
    if (bbReceptor.remaining() == 4) controlador.keyPressed(bbReceptor.getInt(), userId);
  }