当前位置: 首页>>代码示例>>Java>>正文


Java Packet类代码示例

本文整理汇总了Java中ethanjones.cubes.networking.packet.Packet的典型用法代码示例。如果您正苦于以下问题:Java Packet类的具体用法?Java Packet怎么用?Java Packet使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


Packet类属于ethanjones.cubes.networking.packet包,在下文中一共展示了Packet类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: runIf1

import ethanjones.cubes.networking.packet.Packet; //导入依赖的package包/类
private void runIf1(Class<? extends Packet> packetClass, boolean compress) {
	if (socketMonitor.getPacketIDDatabase().contains(packetClass)) {
		if (compress) {
			dataOutputStream.writeByte(2);
		} else {
			dataOutputStream.writeByte(0);
		}
		dataOutputStream.writeInt(socketMonitor.getPacketIDDatabase().get(packetClass));
	} else {
		if (compress) {
			dataOutputStream.writeByte(3);
		} else {
			dataOutputStream.writeByte(1);
		}
		dataOutputStream.writeUTF(packetClass.getName());
		if (socketMonitor.getSide() == Side.Server) {
			socketMonitor.getPacketIDDatabase().sendID(packetClass, socketMonitor);
		}
	}
}
 
开发者ID:RedTroop,项目名称:Cubes_2,代码行数:21,代码来源:SocketOutput.java

示例2: updateIf2

import ethanjones.cubes.networking.packet.Packet; //导入依赖的package包/类
private void updateIf2(boolean compress, Packet packet) {
	if (compress) {
		// Reset
		uncompressedOutput.reset();
		compressionOutput.reset();
		deflater.reset();
		// Write packet
		packet.write(uncompressedDataOutput);
		// Deflate
		deflater.setInput(uncompressedOutput.buffer(), 0, uncompressedOutput.count());
		deflater.finish();
		int length = deflater.deflate(deflateBuffer, 0, deflateBuffer.length);
		while (length > 0) {
			compressionOutput.write(deflateBuffer, 0, length);
			length = deflater.deflate(deflateBuffer, 0, deflateBuffer.length);
		}
		// Write to outputstream
		dataOutputStream.writeInt(compressionOutput.count());
		dataOutputStream.writeInt(uncompressedOutput.count());
		dataOutputStream.write(compressionOutput.buffer(), 0, compressionOutput.count());
	} else {
		packet.write(dataOutputStream);
	}
}
 
开发者ID:RedTroop,项目名称:Cubes_2,代码行数:25,代码来源:SocketOutput.java

示例3: processPackets

import ethanjones.cubes.networking.packet.Packet; //导入依赖的package包/类
@Override
public void processPackets() {
  Side side = Side.getSide();
  PacketQueue packetQueue;
  switch (side) {
    case Client:
      packetQueue = toClient;
      break;
    case Server:
      packetQueue = toServer;
      break;
    default:
      return;
  }
  Packet packet = null;
  Packet p = packetQueue.get();
  while ((packet = p) != null) {
    PacketDirection.checkPacketReceive(packet.getClass(), side);
    packet.handlePacket();
    p=packetQueue.get();
  }
}
 
开发者ID:RedTroop,项目名称:Cubes_2,代码行数:23,代码来源:SingleplayerNetworking.java

示例4: processPackets

import ethanjones.cubes.networking.packet.Packet; //导入依赖的package包/类
@Override
public void processPackets() {
  Side side = Side.getSide();
  PacketQueue packetQueue;
  switch (side) {
    case Client:
      packetQueue = toClient;
      break;
    case Server:
      packetQueue = toServer;
      break;
    default:
      return;
  }
  Packet packet = null;
  while ((packet = packetQueue.get()) != null) {
    PacketDirection.checkPacketReceive(packet.getClass(), side);
    packet.handlePacket();
  }
}
 
开发者ID:RedTroop,项目名称:Cubes,代码行数:21,代码来源:SingleplayerNetworking.java

示例5: sendPacketToServer

import ethanjones.cubes.networking.packet.Packet; //导入依赖的package包/类
public static void sendPacketToServer(Packet packet) {
  if (clientNetworking != null) {
    clientNetworking.sendPacketToServer(packet);
  } else {
    Log.warning("Cannot send " + packet.toString() + " as networking not set up yet");
  }
}
 
开发者ID:RedTroop,项目名称:Cubes_2,代码行数:8,代码来源:NetworkingManager.java

示例6: sendPacketToClient

import ethanjones.cubes.networking.packet.Packet; //导入依赖的package包/类
public static void sendPacketToClient(Packet packet, ClientIdentifier clientIdentifier) {
  if (serverNetworking != null) {
    serverNetworking.sendPacketToClient(packet, clientIdentifier);
  } else {
    Log.warning("Cannot send " + packet.toString() + " as networking not set up yet");
  }
}
 
开发者ID:RedTroop,项目名称:Cubes_2,代码行数:8,代码来源:NetworkingManager.java

示例7: sendPacketToOtherClients

import ethanjones.cubes.networking.packet.Packet; //导入依赖的package包/类
public static void sendPacketToOtherClients(Packet packet, ClientIdentifier otherThan) {
  if (serverNetworking != null && Cubes.getServer() != null) {
    for (ClientIdentifier clientIdentifier : Cubes.getServer().getAllClients()) {
      if (clientIdentifier != otherThan) serverNetworking.sendPacketToClient(packet, clientIdentifier);
    }
  } else {
    Log.warning("Cannot send " + packet.toString() + " as networking not set up yet");
  }
}
 
开发者ID:RedTroop,项目名称:Cubes_2,代码行数:10,代码来源:NetworkingManager.java

示例8: sendPacketToAllClients

import ethanjones.cubes.networking.packet.Packet; //导入依赖的package包/类
public static void sendPacketToAllClients(Packet packet) {
  if (serverNetworking != null && Cubes.getServer() != null) {
    for (ClientIdentifier clientIdentifier : Cubes.getServer().getAllClients()) {
      serverNetworking.sendPacketToClient(packet, clientIdentifier);
    }
  } else {
    Log.warning("Cannot send " + packet.toString() + " as networking not set up yet");
  }
}
 
开发者ID:RedTroop,项目名称:Cubes_2,代码行数:10,代码来源:NetworkingManager.java

示例9: copy

import ethanjones.cubes.networking.packet.Packet; //导入依赖的package包/类
@Override
public Packet copy() {
	PacketArea p = new PacketArea();
	if (Area.isShared()) {
		p.area = this.area;
	} else {
		p.area = new Area(this.area);
	}
	return p;
}
 
开发者ID:RedTroop,项目名称:Cubes_2,代码行数:11,代码来源:PacketArea.java

示例10: sendPacketToServer

import ethanjones.cubes.networking.packet.Packet; //导入依赖的package包/类
@Override
public void sendPacketToServer(Packet packet) {
	if (getNetworkingState() != NetworkingState.Running) {
		Log.warning("Cannot send " + packet.toString() + " as " + getNetworkingState().name());
		return;
	}
	PacketDirection.checkPacketSend(packet.getClass(), Side.Client);
	socketMonitor.getSocketOutput().getPacketQueue().add(packet);
}
 
开发者ID:RedTroop,项目名称:Cubes_2,代码行数:10,代码来源:ClientNetworking.java

示例11: processPackets

import ethanjones.cubes.networking.packet.Packet; //导入依赖的package包/类
public void processPackets() {
	Packet packet = null;
	PacketQueue packetQueue = socketMonitor.getSocketInput().getPacketQueue();
	Packet p = packetQueue.get();
	while ((packet = p) != null) {
		PacketDirection.checkPacketReceive(packet.getClass(), Side.Client);
		packet.handlePacket();
		p = packetQueue.get();
	}
}
 
开发者ID:RedTroop,项目名称:Cubes_2,代码行数:11,代码来源:ClientNetworking.java

示例12: sendPacketToClient

import ethanjones.cubes.networking.packet.Packet; //导入依赖的package包/类
@Override
public void sendPacketToClient(Packet packet, ClientIdentifier clientIdentifier)
		throws UnsupportedOperationException {
	if (getNetworkingState() != NetworkingState.Running) {
		Log.warning("Cannot send " + packet.toString() + " as " + getNetworkingState().name());
		return;
	}
	PacketDirection.checkPacketSend(packet.getClass(), Side.Server);
	clientIdentifier.getSocketMonitor().getSocketOutput().getPacketQueue().add(packet);
}
 
开发者ID:RedTroop,项目名称:Cubes_2,代码行数:11,代码来源:ServerNetworking.java

示例13: processPackets

import ethanjones.cubes.networking.packet.Packet; //导入依赖的package包/类
public void processPackets() {
	for (SocketMonitor socketMonitor : sockets) {
		Packet packet = null;
		PacketQueue packetQueue = socketMonitor.getSocketInput().getPacketQueue();
		
		Packet s = packetQueue.get();
		while ((packet = s) != null) {
			PacketDirection.checkPacketReceive(packet.getClass(), Side.Server);
			packet.handlePacket();
			s=packetQueue.get();
		}
	}
}
 
开发者ID:RedTroop,项目名称:Cubes_2,代码行数:14,代码来源:ServerNetworking.java

示例14: run

import ethanjones.cubes.networking.packet.Packet; //导入依赖的package包/类
@Override
public void run() {
  PairedStreams pair = new PairedStreams();
  DataOutputStream dataOutputStream = new DataOutputStream(pair.output);
  DataInputStream dataInputStream = new DataInputStream(pair.input);

  while (running.get()) {
    try {
      Packet packet = input.waitAndGet();
      if (packet == null) continue;
      if (!packet.shouldSend()) continue;

      Side.setSide(sideOut);
      Packet copy = packet.copy();
      if (copy == packet) throw new IllegalStateException(packet.getClass().getName());

      if (copy == null) {
        Side.setSide(sideIn);
        pair.reset();
        packet.write(dataOutputStream);

        Side.setSide(sideOut);
        pair.updateInput();
        copy = packet.getClass().newInstance();
        copy.read(dataInputStream);
      }

      if (NETWORKING_DEBUG) Log.debug(packet.toString());

      output.add(copy);
    } catch (Exception e) {
      Debug.crash(e);
    }
  }
}
 
开发者ID:RedTroop,项目名称:Cubes,代码行数:36,代码来源:SingleplayerNetworkingThread.java

示例15: copy

import ethanjones.cubes.networking.packet.Packet; //导入依赖的package包/类
@Override
public Packet copy() {
  PacketArea p = new PacketArea();
  if (Area.isShared()) {
    p.area = this.area;
  } else {
    p.area = new Area(this.area);
  }
  return p;
}
 
开发者ID:RedTroop,项目名称:Cubes,代码行数:11,代码来源:PacketArea.java


注:本文中的ethanjones.cubes.networking.packet.Packet类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。