示例#1
0
    protected Object getNextMessage(Object resource) throws Exception {
      Object readMsg = null;
      try {
        readMsg = protocol.read(dataIn);

        if (dataIn.isStreaming()) {
          moreMessages = false;
        }

        return readMsg;
      } catch (SocketTimeoutException e) {
        if (!socket.getKeepAlive()) {
          return null;
        }
      } finally {
        if (readMsg == null) {
          // Protocols can return a null object, which means we're done
          // reading messages for now and can mark the stream for closing later.
          // Also, exceptions can be thrown, in which case we're done reading.
          dataIn.close();
        }
      }

      return null;
    }
  /** {@inheritDoc} */
  public Object getOption(SocketOption name) throws IOException {
    if (!(name instanceof StandardSocketOption)) {
      throw new IllegalArgumentException("Unsupported option " + name);
    }

    StandardSocketOption stdOpt = (StandardSocketOption) name;
    final Socket socket = channel.socket();
    try {
      switch (stdOpt) {
        case SO_SNDBUF:
          return socket.getSendBufferSize();

        case SO_RCVBUF:
          return socket.getReceiveBufferSize();

        case SO_KEEPALIVE:
          return socket.getKeepAlive();

        case SO_REUSEADDR:
          return socket.getReuseAddress();

        case TCP_NODELAY:
          return socket.getTcpNoDelay();

        default:
          throw new IllegalArgumentException("Unsupported option " + name);
      }
    } catch (SocketException e) {
      if (socket.isClosed()) {
        throw Util.initCause(new ClosedChannelException(), e);
      }
      throw e;
    }
  }
示例#3
0
  public static void printSocketParameters(Socket cl) throws SocketException {

    boolean SO_KEEPALIVE = cl.getKeepAlive();
    boolean TCP_NODELAY = cl.getTcpNoDelay();

    int SO_LINGER = cl.getSoLinger();
    int SO_TIMEOUT = cl.getSoTimeout();

    int SO_RCVBUF = cl.getReceiveBufferSize();
    int SO_SNDBUF = cl.getSendBufferSize();

    int trafficClassVal = cl.getTrafficClass();
    /*
     		0 <= trafficClassVal <= 255
    	IPTOS_LOWCOST (0x02)
    	IPTOS_RELIABILITY (0x04)
     			IPTOS_THROUGHPUT (0x08)
    	IPTOS_LOWDELAY (0x10)

    */

    int remotePort = cl.getPort();
    int localPort = cl.getLocalPort();
    String localIP = getIPstr(cl.getLocalAddress());
    String remoteIP = getIPstr(cl.getInetAddress());

    System.out.println("Socket Paramaters :");
    System.out.println("SO_KEEPAILVE = " + SO_KEEPALIVE + " TCP_NODELAY = " + TCP_NODELAY);
    System.out.println("SO_LINGER = " + SO_LINGER + "  SO_TIMEOUT = " + SO_TIMEOUT);
    System.out.println("SO_RCVBUF = " + SO_RCVBUF + "  SO_SNDBUF = " + SO_SNDBUF);
    System.out.println("Traffic Class = " + trafficClassVal);
    System.out.println("Local Address = " + localIP + ":" + localPort);
    System.out.println("Remote Address = " + remoteIP + ":" + remotePort);
  }
 @Override
 public boolean isKeepAlive() {
   try {
     return socket.getKeepAlive();
   } catch (SocketException e) {
     throw new ChannelException(e);
   }
 }
  public static void main(String args[]) {
    try {
      ServerSocket serverSocket = new ServerSocket(4100);
      Socket socket = serverSocket.accept();
      System.out.println(socket.getKeepAlive());

      BufferedReader in = new BufferedReader(new InputStreamReader(socket.getInputStream()));
      System.out.println(in.readLine());
      serverSocket.close();
    } catch (Exception e) {
      System.err.print(e);
    }
  }
 @Override
 public boolean getKeepAlive() throws SocketException {
   return sock.getKeepAlive();
 }
示例#7
0
 public boolean getKeepAlive() throws SocketException {
   return mSocket.getKeepAlive();
 }