Search in sources :

Example 1 with Connector

use of com.jme3.network.kernel.Connector 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)

Example 2 with Connector

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

the class DefaultClient method configureChannels.

protected void configureChannels(long tempId, int[] ports) {
    try {
        for (int i = 0; i < ports.length; i++) {
            Connector c = connectorFactory.createConnector(i, ports[i]);
            ConnectorAdapter ca = new ConnectorAdapter(c, dispatcher, dispatcher, true);
            int ch = channels.size();
            channels.add(ca);
            // Need to send the connection its hook-up registration
            // and start it.
            ca.start();
            ClientRegistrationMessage reg;
            reg = new ClientRegistrationMessage();
            reg.setId(tempId);
            reg.setReliable(true);
            send(ch, reg, false);
        }
    } catch (IOException e) {
        throw new RuntimeException("Error configuring channels", e);
    }
}
Also used : Connector(com.jme3.network.kernel.Connector) IOException(java.io.IOException) ClientRegistrationMessage(com.jme3.network.message.ClientRegistrationMessage)

Aggregations

Message (com.jme3.network.Message)1 Connector (com.jme3.network.kernel.Connector)1 ConnectorException (com.jme3.network.kernel.ConnectorException)1 ClientRegistrationMessage (com.jme3.network.message.ClientRegistrationMessage)1 IOException (java.io.IOException)1 ByteBuffer (java.nio.ByteBuffer)1