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);
}
}
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);
}
}
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);
}
}
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);
}
}
Aggregations