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


Java PacketHeartbeat类代码示例

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


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

示例1: update

import de.gymdon.inf1315.game.packet.PacketHeartbeat; //导入依赖的package包/类
public void update() {
if (server.clientList.isEmpty())
    return;
for (Iterator<Remote> i = server.clientList.iterator(); i.hasNext();) {
    Remote r = i.next();
    try {
	DataInputStream din = r.getInputStream();
	if (din.available() >= 2) {
	    short id = din.readShort();
	    Packet p = Packet.newPacket(id, r);
	    if (p != null)
		p.handlePacket();
	    else
		r.kick("Invalid Packet");
	}
	if (r.getSocket().isClosed())
	    r.leave("Socket closed");
	long now = System.currentTimeMillis();
	if (now - r.getLastPacketTime() >= 2000) {
	    PacketHeartbeat heartbeat = new PacketHeartbeat(r);
	    heartbeat.response = false;
	    byte[] bytes = new byte[43];
	    new Random().nextBytes(bytes);
	    heartbeat.payload = bytes;
	    heartbeat.send();
	}
    } catch (Exception e) {
	r.leave(e.getMessage() == null ? e.getClass().getSimpleName() : e.getMessage());
    }
    if (r.left())
	i.remove();
}
   }
 
开发者ID:GymDon-P-Q11Info-13-15,项目名称:game-server,代码行数:34,代码来源:ConnectionHandler.java

示例2: processPackets

import de.gymdon.inf1315.game.packet.PacketHeartbeat; //导入依赖的package包/类
public void processPackets() {
if(left())
    return;
try {
    DataInputStream din = getInputStream();
    if (din.available() >= 2) {
	short id = din.readShort();
	Packet p = Packet.newPacket(id, this);
	if (p != null)
	    p.handlePacket();
	else
	    kick("Invalid Packet");
    }
    if (getSocket().isClosed())
	leave("Socket closed");
    long now = System.currentTimeMillis();
    if(lastPacket == 0)
	lastPacket = System.currentTimeMillis();
    if (now - this.getLastPacketTime() >= 2100) {
	PacketHeartbeat heartbeat = new PacketHeartbeat(this);
	heartbeat.response = false;
	byte[] bytes = new byte[43];
	new Random().nextBytes(bytes);
	heartbeat.payload = bytes;
	heartbeat.send();
    }
} catch (Exception e) {
    leave(e.getMessage() == null ? e.getClass().getSimpleName() : e.getMessage());
}
   }
 
开发者ID:GymDon-P-Q11Info-13-15,项目名称:game-client,代码行数:31,代码来源:Server.java


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