Search in sources :

Example 1 with ConnectorException

use of com.jme3.network.kernel.ConnectorException in project jmonkeyengine by jMonkeyEngine.

the class SocketConnector method close.

public void close() {
    checkClosed();
    try {
        Socket temp = sock;
        sock = null;
        connected.set(false);
        temp.close();
    } catch (IOException e) {
        throw new ConnectorException("Error closing socket for:" + remoteAddress, e);
    }
}
Also used : ConnectorException(com.jme3.network.kernel.ConnectorException) IOException(java.io.IOException) Socket(java.net.Socket)

Example 2 with ConnectorException

use of com.jme3.network.kernel.ConnectorException in project jmonkeyengine by jMonkeyEngine.

the class UdpConnector method read.

public ByteBuffer read() {
    checkClosed();
    try {
        DatagramPacket packet = new DatagramPacket(buffer, buffer.length);
        sock.receive(packet);
        // Wrap it in a ByteBuffer for the caller
        return ByteBuffer.wrap(buffer, 0, packet.getLength());
    } catch (IOException e) {
        if (!connected.get()) {
            // Nothing to see here... just move along
            return null;
        }
        throw new ConnectorException("Error reading from connection to:" + remoteAddress, e);
    }
}
Also used : ConnectorException(com.jme3.network.kernel.ConnectorException) IOException(java.io.IOException)

Example 3 with ConnectorException

use of com.jme3.network.kernel.ConnectorException in project jmonkeyengine by jMonkeyEngine.

the class UdpConnector method write.

public void write(ByteBuffer data) {
    checkClosed();
    try {
        DatagramPacket p = new DatagramPacket(data.array(), data.position(), data.remaining(), remoteAddress);
        sock.send(p);
    } catch (IOException e) {
        throw new ConnectorException("Error writing to connection:" + remoteAddress, e);
    }
}
Also used : ConnectorException(com.jme3.network.kernel.ConnectorException) IOException(java.io.IOException)

Example 4 with ConnectorException

use of com.jme3.network.kernel.ConnectorException in project jmonkeyengine by jMonkeyEngine.

the class ConnectorAdapter method run.

public void run() {
    MessageProtocol protocol = new MessageProtocol();
    try {
        while (go.get()) {
            ByteBuffer buffer = connector.read();
            if (buffer == null) {
                if (go.get()) {
                    throw new ConnectorException("Connector closed.");
                } else {
                    // from a closed/closing connector
                    break;
                }
            }
            protocol.addBuffer(buffer);
            Message m = null;
            while ((m = protocol.getMessage()) != null) {
                m.setReliable(reliable);
                dispatch(m);
            }
        }
    } catch (Exception e) {
        handleError(e);
    }
}
Also used : Message(com.jme3.network.Message) ConnectorException(com.jme3.network.kernel.ConnectorException) ByteBuffer(java.nio.ByteBuffer) ConnectorException(com.jme3.network.kernel.ConnectorException)

Aggregations

ConnectorException (com.jme3.network.kernel.ConnectorException)4 IOException (java.io.IOException)3 Message (com.jme3.network.Message)1 Socket (java.net.Socket)1 ByteBuffer (java.nio.ByteBuffer)1