Package com.esotericsoftware.kryonet

Examples of com.esotericsoftware.kryonet.Connection


        IntSerializer.put(buffer, handler.objectID, true);
      }

      public <T> T readObjectData (ByteBuffer buffer, Class<T> type) {
        int objectID = IntSerializer.get(buffer, true);
        Connection connection = (Connection)Kryo.getContext().get("connection");
        Object object = getRegisteredObject(connection, objectID);
        if (WARN && object == null) warn("kryonet", "Unknown object ID " + objectID + " for connection: " + connection);
        return (T)object;
      }
    });
View Full Code Here


        Object reply = messageObjectReceived((MessageCreateValue) obj);
        conn.sendTCP(reply);
      } else if (obj instanceof MessageSplitEnd) {
        messageObjectEndReceived((MessageSplitEnd) obj);
      } else if (obj instanceof RequestObject) {
        Connection dest = null;

        RequestObject request = (RequestObject) obj;
        pendingRequest.put(request.getGuid(), conn);

        int min = Integer.MAX_VALUE;
        for (Connection connDest : server.getConnections()) {

          if (conn.getID() != connDest.getID()
              && connDest.getReturnTripTime() < min) {
            min = connDest.getReturnTripTime();
            dest = connDest;
          }
        }

        dest.sendTCP(obj);
      }
    } catch (Exception ex) {
      Logger.getLogger(getClass()).error(
          "Error occur when receiving message", ex);
    }
View Full Code Here

    if (encaps == null) {
      encaps = new ObjectSender();

      sendingObjets.put(obj.getId(), encaps);

      Connection dest = pendingRequest.get(obj.getId());
      if (dest != null) {
        // The object we received is for a specific player
        sendObject(dest, obj.getId(), encaps);
      } else {
        // The object we received is a new one, every one need to get it
View Full Code Here

        Object reply = messageObjectReceived((MessageCreateValue) obj);
        conn.sendTCP(reply);
      } else if (obj instanceof MessageSplitEnd) {
        messageObjectEndReceived((MessageSplitEnd) obj);
      } else if (obj instanceof RequestObject) {
        Connection dest = null;

        RequestObject request = (RequestObject) obj;
        pendingRequest.put(request.getGuid(), conn);

        int min = Integer.MAX_VALUE;
        for (Connection connDest : server.getConnections()) {

          if (conn.getID() != connDest.getID()
              && connDest.getReturnTripTime() < min) {
            min = connDest.getReturnTripTime();
            dest = connDest;
          }
        }

        dest.sendTCP(obj);
      }
    } catch (Exception ex) {
      ex.printStackTrace();
    }
View Full Code Here

    if (encaps == null) {
      encaps = new ObjectSender();

      sendingObjets.put(obj.getId(), encaps);

      Connection dest = pendingRequest.get(obj.getId());
      if (dest != null) {
        // The object we received is for a specific player
        sendObject(dest, obj.getId(), encaps);
      } else {
        // The object we received is a new one, every one need to get it
View Full Code Here

  }

  private void requestReceived(Connection conn, RequestCampaignClient request) {
    System.out.println("request received");

    Connection dest = null;

    int min = Integer.MAX_VALUE;
    for (Connection destConn : server.getConnections()) {
      if (conn.getID() != destConn.getID()
          && destConn.getReturnTripTime() < min) {
        min = destConn.getReturnTripTime();
        dest = destConn;
      }
    }

    dest.sendTCP(new RequestIdsServer());
  }
View Full Code Here

        output.writeInt(handler.objectID, true);
      }

      public Object read (Kryo kryo, Input input, Class type) {
        int objectID = input.readInt(true);
        Connection connection = (Connection)kryo.getContext().get("connection");
        Object object = getRegisteredObject(connection, objectID);
        if (WARN && object == null) warn("kryonet", "Unknown object ID " + objectID + " for connection: " + connection);
        return object;
      }
    });
View Full Code Here

        output.writeInt(handler.objectID, true);
      }

      public Object read (Kryo kryo, Input input, Class type) {
        int objectID = input.readInt(true);
        Connection connection = (Connection)kryo.getContext().get("connection");
        Object object = getRegisteredObject(connection, objectID);
        if (WARN && object == null) warn("kryonet", "Unknown object ID " + objectID + " for connection: " + connection);
        return object;
      }
    });
View Full Code Here

  /** Serializes an object registered with an ObjectSpace so the receiving side gets a {@link RemoteObject} proxy rather than the
   * bytes for the serialized object.
   * @author Nathan Sweet <misc@n4te.com> */
  static public class RemoteObjectSerializer extends Serializer {
    public void write (Kryo kryo, Output output, Object object) {
      Connection connection = (Connection)kryo.getContext().get("connection");
      int id = getRegisteredID(connection, object);
      if (id == Integer.MAX_VALUE) throw new KryoNetException("Object not found in an ObjectSpace: " + object);
      output.writeInt(id, true);
    }
View Full Code Here

      output.writeInt(id, true);
    }

    public Object read (Kryo kryo, Input input, Class type) {
      int objectID = input.readInt(true);
      Connection connection = (Connection)kryo.getContext().get("connection");
      return ObjectSpace.getRemoteObject(connection, objectID, type);
    }
View Full Code Here

TOP

Related Classes of com.esotericsoftware.kryonet.Connection

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.