Search in sources :

Example 16 with Message

use of com.jme3.network.Message in project jmonkeyengine by jMonkeyEngine.

the class RmiSerializer method writeType.

private void writeType(ByteBuffer buffer, Class<?> clazz) throws IOException {
    if (clazz == void.class) {
        buffer.putShort((short) 0);
    } else {
        SerializerRegistration reg = Serializer.getSerializerRegistration(clazz);
        if (reg == null) {
            logger.log(Level.WARNING, "Unknown class: {0}", clazz);
            // prevents message from being serialized
            throw new IOException();
        }
        buffer.putShort(reg.getId());
    }
}
Also used : IOException(java.io.IOException) SerializerRegistration(com.jme3.network.serializing.SerializerRegistration)

Example 17 with Message

use of com.jme3.network.Message in project jmonkeyengine by jMonkeyEngine.

the class KernelAdapter method createAndDispatch.

protected void createAndDispatch(Envelope env) {
    MessageProtocol protocol = getMessageBuffer(env.getSource());
    byte[] data = env.getData();
    ByteBuffer buffer = ByteBuffer.wrap(data);
    int count = protocol.addBuffer(buffer);
    if (count == 0) {
        // connections.
        if (!reliable) {
            // Log some additional information about the packet.
            int len = Math.min(10, data.length);
            StringBuilder sb = new StringBuilder();
            for (int i = 0; i < len; i++) {
                sb.append("[" + Integer.toHexString(data[i]) + "]");
            }
            log.log(Level.FINE, "First 10 bytes of incomplete nessage:" + sb);
            throw new RuntimeException("Envelope contained incomplete data:" + env);
        }
    }
    // Should be complete... and maybe we should check but we don't
    Message m = null;
    while ((m = protocol.getMessage()) != null) {
        m.setReliable(reliable);
        dispatch(env.getSource(), m);
    }
}
Also used : Message(com.jme3.network.Message) ClientRegistrationMessage(com.jme3.network.message.ClientRegistrationMessage) ByteBuffer(java.nio.ByteBuffer) Endpoint(com.jme3.network.kernel.Endpoint)

Example 18 with Message

use of com.jme3.network.Message in project jmonkeyengine by jMonkeyEngine.

the class ZIPSerializer method readObject.

@SuppressWarnings("unchecked")
public <T> T readObject(ByteBuffer data, Class<T> c) throws IOException {
    try {
        ZIPCompressedMessage result = new ZIPCompressedMessage();
        byte[] byteArray = new byte[data.remaining()];
        data.get(byteArray);
        ZipInputStream in = new ZipInputStream(new ByteArrayInputStream(byteArray));
        in.getNextEntry();
        ByteArrayOutputStream out = new ByteArrayOutputStream();
        byte[] tmp = new byte[9012];
        int read;
        while (in.available() > 0 && ((read = in.read(tmp)) > 0)) {
            out.write(tmp, 0, read);
        }
        in.closeEntry();
        out.flush();
        in.close();
        result.setMessage((Message) Serializer.readClassAndObject(ByteBuffer.wrap(out.toByteArray())));
        return (T) result;
    } catch (Exception e) {
        e.printStackTrace();
        throw new IOException(e.toString());
    }
}
Also used : ZipInputStream(java.util.zip.ZipInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) ZIPCompressedMessage(com.jme3.network.message.ZIPCompressedMessage) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) IOException(java.io.IOException)

Example 19 with Message

use of com.jme3.network.Message in project jmonkeyengine by jMonkeyEngine.

the class ZIPSerializer method writeObject.

public void writeObject(ByteBuffer buffer, Object object) throws IOException {
    if (!(object instanceof ZIPCompressedMessage))
        return;
    ZIPCompressedMessage zipMessage = (ZIPCompressedMessage) object;
    Message message = zipMessage.getMessage();
    ByteBuffer tempBuffer = ByteBuffer.allocate(512000);
    Serializer.writeClassAndObject(tempBuffer, message);
    ByteArrayOutputStream byteArrayOutput = new ByteArrayOutputStream();
    ZipOutputStream zipOutput = new ZipOutputStream(byteArrayOutput);
    zipOutput.setLevel(zipMessage.getLevel());
    ZipEntry zipEntry = new ZipEntry("zip");
    zipOutput.putNextEntry(zipEntry);
    tempBuffer.flip();
    zipOutput.write(tempBuffer.array(), 0, tempBuffer.limit());
    zipOutput.flush();
    zipOutput.closeEntry();
    zipOutput.close();
    buffer.put(byteArrayOutput.toByteArray());
}
Also used : Message(com.jme3.network.Message) ZIPCompressedMessage(com.jme3.network.message.ZIPCompressedMessage) ZipOutputStream(java.util.zip.ZipOutputStream) ZipEntry(java.util.zip.ZipEntry) ZIPCompressedMessage(com.jme3.network.message.ZIPCompressedMessage) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ByteBuffer(java.nio.ByteBuffer)

Example 20 with Message

use of com.jme3.network.Message in project jmonkeyengine by jMonkeyEngine.

the class GZIPSerializer method writeObject.

public void writeObject(ByteBuffer buffer, Object object) throws IOException {
    if (!(object instanceof GZIPCompressedMessage))
        return;
    Message message = ((GZIPCompressedMessage) object).getMessage();
    ByteBuffer tempBuffer = ByteBuffer.allocate(512000);
    Serializer.writeClassAndObject(tempBuffer, message);
    ByteArrayOutputStream byteArrayOutput = new ByteArrayOutputStream();
    GZIPOutputStream gzipOutput = new GZIPOutputStream(byteArrayOutput);
    tempBuffer.flip();
    gzipOutput.write(tempBuffer.array(), 0, tempBuffer.limit());
    gzipOutput.flush();
    gzipOutput.finish();
    gzipOutput.close();
    buffer.put(byteArrayOutput.toByteArray());
}
Also used : GZIPCompressedMessage(com.jme3.network.message.GZIPCompressedMessage) GZIPCompressedMessage(com.jme3.network.message.GZIPCompressedMessage) Message(com.jme3.network.Message) GZIPOutputStream(java.util.zip.GZIPOutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ByteBuffer(java.nio.ByteBuffer)

Aggregations

IOException (java.io.IOException)6 Message (com.jme3.network.Message)5 ClientRegistrationMessage (com.jme3.network.message.ClientRegistrationMessage)5 ByteArrayOutputStream (java.io.ByteArrayOutputStream)4 ByteBuffer (java.nio.ByteBuffer)4 GhostControl (com.jme3.bullet.control.GhostControl)2 Server (com.jme3.network.Server)2 Endpoint (com.jme3.network.kernel.Endpoint)2 ChannelInfoMessage (com.jme3.network.message.ChannelInfoMessage)2 GZIPCompressedMessage (com.jme3.network.message.GZIPCompressedMessage)2 ZIPCompressedMessage (com.jme3.network.message.ZIPCompressedMessage)2 RpcCallMessage (com.jme3.network.service.rpc.msg.RpcCallMessage)2 ByteArrayInputStream (java.io.ByteArrayInputStream)2 BulletAppState (com.jme3.bullet.BulletAppState)1 BoxCollisionShape (com.jme3.bullet.collision.shapes.BoxCollisionShape)1 CompoundCollisionShape (com.jme3.bullet.collision.shapes.CompoundCollisionShape)1 SphereCollisionShape (com.jme3.bullet.collision.shapes.SphereCollisionShape)1 RigidBodyControl (com.jme3.bullet.control.RigidBodyControl)1 BitmapText (com.jme3.font.BitmapText)1 KeyTrigger (com.jme3.input.controls.KeyTrigger)1