Search in sources :

Example 6 with Message

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

the class NioEndpoint method close.

public void close(boolean flushData) {
    if (flushData) {
        closing = true;
        // Enqueue a close marker message to let the server
        // know we should close
        send(CLOSE_MARKER, false, true);
        return;
    }
    try {
        // Note: even though we may be disconnected from the socket.isConnected()
        // standpoint, it's still safest to tell the kernel so that it can be sure
        // to stop managing us gracefully.
        kernel.closeEndpoint(this);
    } catch (IOException e) {
        throw new KernelException("Error closing endpoint for socket:" + socket, e);
    }
}
Also used : IOException(java.io.IOException) KernelException(com.jme3.network.kernel.KernelException)

Example 7 with Message

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

the class RpcConnection method callAndWait.

/**
     *  Performs a remote procedure call with the specified arguments and waits
     *  for the response.  Both the outbound message and inbound response will
     *  be sent on the specified channel.
     */
public Object callAndWait(byte channel, short objId, short procId, Object... args) {
    RpcCallMessage msg = new RpcCallMessage(sequenceNumber.getAndIncrement(), channel, objId, procId, args);
    // Need to register an object so we can wait for the response.
    // ...before we send it.  Just in case.
    ResponseHolder holder = new ResponseHolder(msg);
    responses.put(msg.getMessageId(), holder);
    if (log.isLoggable(Level.FINEST)) {
        log.log(Level.FINEST, "Sending:{0}  on channel:{1}", new Object[] { msg, channel });
    }
    // so it doesn't do the check.
    if (channel >= 0) {
        connection.send(channel, msg);
    } else {
        connection.send(msg);
    }
    return holder.getResponse();
}
Also used : RpcCallMessage(com.jme3.network.service.rpc.msg.RpcCallMessage)

Example 8 with Message

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

the class RpcHostedService method onInitialize.

/**
     *  Used internally to setup the message delegator that will
     *  handle HostedConnection specific messages and forward them
     *  to that connection's RpcConnection.
     */
@Override
protected void onInitialize(HostedServiceManager serviceManager) {
    Server server = serviceManager.getServer();
    // A general listener for forwarding the messages
    // to the client-specific handler
    this.delegator = new SessionDataDelegator(RpcConnection.class, ATTRIBUTE_NAME, true);
    server.addMessageListener(delegator, delegator.getMessageTypes());
    if (log.isLoggable(Level.FINEST)) {
        log.log(Level.FINEST, "Registered delegator for message types:{0}", Arrays.asList(delegator.getMessageTypes()));
    }
}
Also used : Server(com.jme3.network.Server) SessionDataDelegator(com.jme3.network.util.SessionDataDelegator)

Example 9 with Message

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

the class RpcHostedService method terminate.

/**
     *  Used internally to remove the message delegator from the
     *  server.
     */
@Override
public void terminate(HostedServiceManager serviceManager) {
    Server server = serviceManager.getServer();
    server.removeMessageListener(delegator, delegator.getMessageTypes());
}
Also used : Server(com.jme3.network.Server)

Example 10 with Message

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

the class RollingTheMonkey method reset.

private void reset() {
    // Reset the pickups
    for (Spatial pickUp : pickUps.getChildren()) {
        GhostControl pickUpControl = pickUp.getControl(GhostControl.class);
        if (pickUpControl != null) {
            pickUpControl.setEnabled(true);
        }
        pickUp.setLocalScale(1.0f);
    }
    // Reset the player
    player.setPhysicsLocation(PLAYER_START.clone());
    player.setAngularVelocity(Vector3f.ZERO.clone());
    player.setLinearVelocity(Vector3f.ZERO.clone());
    // Reset the score
    score = 0;
    // Reset the message
    messageText.setLocalScale(0.0f);
}
Also used : Spatial(com.jme3.scene.Spatial) GhostControl(com.jme3.bullet.control.GhostControl)

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