Package java.net

Examples of java.net.SocketException


    Context context = Kryo.getContext();
    context.put("connection", this);
    context.put("connectionID", id);
    try {
      if (address == null) throw new SocketException("Connection is closed.");

      int length = udp.send(this, object, address);
      if (length == 0) {
        if (TRACE) trace("kryonet", this + " UDP had nothing to send.");
      } else if (DEBUG) {
View Full Code Here


    }
  }

  public Object readObject (Connection connection) throws IOException {
    SocketChannel socketChannel = this.socketChannel;
    if (socketChannel == null) throw new SocketException("Connection is closed.");

    if (currentObjectLength == 0) {
      // Read the length of the next object from the socket.
      if (!IntSerializer.canRead(readBuffer, true)) {
        readBuffer.compact();
        int bytesRead = socketChannel.read(readBuffer);
        readBuffer.flip();
        if (bytesRead == -1) throw new SocketException("Connection is closed.");
        lastReadTime = System.currentTimeMillis();

        if (!IntSerializer.canRead(readBuffer, true)) return null;
      }
      currentObjectLength = IntSerializer.get(readBuffer, true);

      if (currentObjectLength <= 0) throw new SerializationException("Invalid object length: " + currentObjectLength);
      if (currentObjectLength > readBuffer.capacity())
        throw new SerializationException("Unable to read object larger than read buffer: " + currentObjectLength);
    }

    int length = currentObjectLength;
    if (readBuffer.remaining() < length) {
      // Read the bytes for the next object from the socket.
      readBuffer.compact();
      int bytesRead = socketChannel.read(readBuffer);
      readBuffer.flip();
      if (bytesRead == -1) throw new SocketException("Connection is closed.");
      lastReadTime = System.currentTimeMillis();

      if (readBuffer.remaining() < length) return null;
    }
    currentObjectLength = 0;
View Full Code Here

    }
  }

  private boolean writeToSocket (ByteBuffer buffer) throws IOException {
    SocketChannel socketChannel = this.socketChannel;
    if (socketChannel == null) throw new SocketException("Connection is closed.");

    while (buffer.hasRemaining()) {
      if (bufferPositionFix) {
        buffer.compact();
        buffer.flip();
View Full Code Here

  /**
   * This method is thread safe.
   */
  public int send (Connection connection, Object object) throws IOException {
    SocketChannel socketChannel = this.socketChannel;
    if (socketChannel == null) throw new SocketException("Connection is closed.");
    synchronized (writeLock) {
      tempWriteBuffer.clear();
      tempWriteBuffer.position(5); // Allow room for the data length.

      // Write data.
View Full Code Here

    }
  }

  public InetSocketAddress readFromAddress () throws IOException {
    DatagramChannel datagramChannel = this.datagramChannel;
    if (datagramChannel == null) throw new SocketException("Connection is closed.");
    lastCommunicationTime = System.currentTimeMillis();
    return (InetSocketAddress)datagramChannel.receive(readBuffer);
  }
View Full Code Here

  /**
   * This method is thread safe.
   */
  public int send (Connection connection, Object object, SocketAddress address) throws IOException {
    DatagramChannel datagramChannel = this.datagramChannel;
    if (datagramChannel == null) throw new SocketException("Connection is closed.");
    synchronized (writeLock) {
      try {
        Context context = Kryo.getContext();
        context.put("connection", connection);
        context.setRemoteEntityID(connection.id);
View Full Code Here

    testCreateThrowable(
        new CommunicationException(new ConnectException(
            "A test java.net.ConnectException"), //$NON-NLS-1$
            "Test Communication Exception with a ConnectException in it"), //$NON-NLS-1$
        SQLStates.CONNECTION_EXCEPTION_SQLCLIENT_UNABLE_TO_ESTABLISH_SQLCONNECTION);
    testCreateThrowable(new CommunicationException(new SocketException(
        "A test java.net.SocketException"), //$NON-NLS-1$
        "Test Communication Exception with a SocketException in it"), //$NON-NLS-1$
        SQLStates.CONNECTION_EXCEPTION_STALE_CONNECTION);
    testCreateThrowable(
        new TeiidException(new SocketTimeoutException(
View Full Code Here

   * @exception SocketException if Socket is not open.
   * @since 1.4.5
   */
  public boolean isConnected() throws SocketException {
    if(isOpen()==false)
      throw new SocketException("Connection is no more open!");
    else
      return true;
  }
View Full Code Here

        temp = temp + NEW_LINE;
      if(dataModeOUT != DataMode.OBJECT) {
        out.write(temp.getBytes(charset));
        out.flush();
      }
      if(true) throw new SocketException("Timeout");
    }
  }
View Full Code Here

   * @see #doQuit(String)
   * @see #close()
   */
  public void connect() throws IOException {
    if (level != 0) // otherwise disconnected or connect
      throw new SocketException("Socket closed or already open ("+ level +")");
    IOException exception = null;
    if (trustManagers.size() == 0)
      addTrustManager(new SSLDefaultTrustManager());
    SSLSocketFactory sf = null;
    SSLSocket s = null;
View Full Code Here

TOP

Related Classes of java.net.SocketException

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.