Package org.cspoker.server.xml.sockets

Examples of org.cspoker.server.xml.sockets.ClientContext


      int numBytesRead = client.read(buffer);

      if (numBytesRead == -1) {
        // No more bytes can be read from the channel
        logger.debug("channel has reached end-of-stream");
        ClientContext context = getContext(key, client);
        context.closeConnection();
      } else {
        logger.trace("Reading " + numBytesRead + " bytes from socket");
        // To read the bytes, flip the buffer
        buffer.flip();
        ClientContext context = getContext(key, client);
        StringBuilder stringBuilder = context.getBuffer();

        while (buffer.hasRemaining()) {
          boolean hasEnded = filterUntilEndNode();

          CharBuffer decoded = decoder.decode(filteredBuffer);
          logger.trace("Reading: \n" + decoded);
          stringBuilder.append(decoded);
          if (hasEnded) {
            endNode(stringBuilder, context);
          }
        }
      }
    } catch (IOException e) {
      logger.debug("Exception reading from socket, closing socket: "+e.getMessage());
      ClientContext context = getContext(key, client);
      context.closeConnection();
      // Rethrow exception as declared
      throw (e);
    }

  }
View Full Code Here


    }

  }

  private ClientContext getContext(SelectionKey key, SocketChannel client) {
    ClientContext context = (ClientContext) (key.attachment());
    if (context == null) {
      context = new ClientContext(client, selector, cspokerServer);
      key.attach(context);
    }
    return context;

  }
View Full Code Here

TOP

Related Classes of org.cspoker.server.xml.sockets.ClientContext

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.