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


Java Connection.sendTCP方法代码示例

本文整理汇总了Java中com.esotericsoftware.kryonet.Connection.sendTCP方法的典型用法代码示例。如果您正苦于以下问题:Java Connection.sendTCP方法的具体用法?Java Connection.sendTCP怎么用?Java Connection.sendTCP使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.esotericsoftware.kryonet.Connection的用法示例。


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

示例1: onNewConnection

import com.esotericsoftware.kryonet.Connection; //导入方法依赖的package包/类
private synchronized void onNewConnection(Connection con) {
	Gdx.app.log("Server", "Client connected");

	Player p = PlayerUtils.getRandomPlayer(players.values());
	players.put(playersJoinedCount, p);
	clients.put(playersJoinedCount, new ServerPlayer(p));
	connections.put(playersJoinedCount, con);

	// Inform the other clients
	server.sendToAllExceptTCP(con.getID(), new PlayerJoinedMessage(
			playersJoinedCount, players.get(playersJoinedCount)));

	// Send the setup response
	con.sendTCP(
			new GameSetupMessage(players, playersJoinedCount, settings));

	playersJoinedCount++;
}
 
开发者ID:eskalon,项目名称:ProjektGG,代码行数:19,代码来源:GameServer.java

示例2: handleCreateMotorMessage

import com.esotericsoftware.kryonet.Connection; //导入方法依赖的package包/类
private void handleCreateMotorMessage(final Connection conn, final CreateMotorMessage msg) {
	Thread createMotor = new Thread(){
		@Override
		public void run(){
			LocalEV3.get().getLED().setPattern(9);
			
			if(motorPorts.containsKey(msg.getPort())){
				if(createMotorEndpoint( motorPorts.get(msg.getPort()),msg.getMotorType(),msg.getNetworkPort() )){
					conn.sendTCP(BrickMessages.createEndpointCreatedMessage(true, msg.getPort(), "Motor endpoint created: "+msg.getPort(), false, true));		
				}else{
					isBlocked = true;
					System.out.println("System got blocked by handleCreateMotorMethod");
					conn.sendTCP(BrickMessages.createEndpointCreatedMessage(false, msg.getPort(), "Motor endpoint not created: "+msg.getPort(), false, true));						
					
				}
			}else{
				conn.sendTCP(BrickMessages.createEndpointCreatedMessage(false, msg.getPort(), "Port not found!"+msg.getPort(), false, true));
			}	
		}
		};
	creationThreads.add(createMotor);
	//createMotor.start();
}
 
开发者ID:Echtzeitsysteme,项目名称:mindroid,代码行数:24,代码来源:DeviceManager.java

示例3: handle

import com.esotericsoftware.kryonet.Connection; //导入方法依赖的package包/类
@Override
public void handle(Connection connection, RetrieveItemRewardPacket packet)
{
    Character character = gameDataRetreiver.getUserCharacterByConnectionId(connection.getID());
    CharactersQuests quest = findSuiteQuest(character.getQuests(), packet.getQuestName());
    CharactersQuestsItemReward itemReward = findSuiteItemReward(quest.getItemsReward(), packet.getItemIdentifier());
    PlayerCharacter player = (PlayerCharacter) gameContainer.getObject(character.getId());
    InventoryPosition inventoryPosition = new InventoryPosition(packet.getDesiredInventoryPage(),
            packet.getDesiredInventoryX(), packet.getDesiredInventoryY());
    Item gameItem;
    if (itemReward.getNumberOfItems() == packet.getNumberOfItems())
        gameItem = GameItemsFactory.produce(itemReward.getItemIdentifier(), itemReward.getNumberOfItems(),
                IdSupplier.getId(), inventoryPosition);
    else
        throw new NotImplementedException("Not implemented yet");

    player.addItemAllowStacking(gameItem);
    connection.sendTCP(PacketsMaker.makeItemRewardRemovePacket(packet.getItemIdentifier(),
            itemReward.getNumberOfItems()));
    connection.sendTCP(PacketsMaker.makeItemPacket(gameItem));
}
 
开发者ID:MMORPG-Prototype,项目名称:MMORPG_Prototype,代码行数:22,代码来源:RetrieveItemRewardPacketHandler.java

示例4: handle

import com.esotericsoftware.kryonet.Connection; //导入方法依赖的package包/类
@Override
public void handle(Connection connection, ItemUsagePacket packet)
{
	int characterId = gameData.getCharacterIdByConnectionId(connection.getID());
	PlayerCharacter itemUser = (PlayerCharacter)playState.getObject(characterId);
	if(itemUser == null)
		throw new PlayerUsingItemNotFoundException();
	Monster target = (Monster)playState.getObject(packet.getTargetId());
	try
	{
		itemUser.useItem(packet.getItemId(), target, (PacketsSender)playState);
		connection.sendTCP(packet);
	}
	catch(OutOfStockException e)
	{
		connection.sendTCP(PacketsMaker.makeUnacceptableOperationPacket("Your item stack was depleted"));
	}
}
 
开发者ID:MMORPG-Prototype,项目名称:MMORPG_Prototype,代码行数:19,代码来源:ItemUsagePacketHandler.java

示例5: handle

import com.esotericsoftware.kryonet.Connection; //导入方法依赖的package包/类
@Override 
public void handle(Connection connection, TakingGoldFromContainerPacket packet)
{
	long characterId = gameData.getCharacterIdByConnectionId(connection.getID());
	PlayerCharacter player = (PlayerCharacter)playState.getObject(characterId);
	GameContainer container = playState.getContainer(packet.getContainerId());
	int gold = container.getGoldAmount();
	if(gold > 0)
	{
		connection.sendTCP(PacketsMaker.makeGoldReceivePacket(gold));
		server.sendToAllTCP(PacketsMaker.makeContainerGoldRemovalPacket(packet.getContainerId(), gold));
		container.setGoldAmount(0);
		player.addGold(gold);
	}
	else
		connection.sendTCP(PacketsMaker.makeUnacceptableOperationPacket("There is no gold left in this container"));
	
}
 
开发者ID:MMORPG-Prototype,项目名称:MMORPG_Prototype,代码行数:19,代码来源:TakingGoldFromContainerPacketHandler.java

示例6: handle

import com.esotericsoftware.kryonet.Connection; //导入方法依赖的package包/类
@Override
public void handle(Connection connection, ScriptCodePacket packet)
{
	User user = authenticatedClientsKeyClientId.get(connection.getID());
	if(!user.getRole().equals(UserRole.ADMIN))
	{
		connection.sendTCP(PacketsMaker.makeScriptExecutionErrorPacket("You must be admin to do that"));
		return;
	}
	
	try
	{
		Object result = playState.executeCode(packet.getCode(), user.getId());
		if(result != null)
			connection.sendTCP(PacketsMaker.makeScriptResultInfoPacket(result.toString()));
		
	}catch(ScriptException e)
	{
		connection.sendTCP(PacketsMaker.makeScriptExecutionErrorPacket(e.getMessage()));
	}
}
 
开发者ID:MMORPG-Prototype,项目名称:MMORPG_Prototype,代码行数:22,代码来源:ScriptCodePacketHandler.java

示例7: handle

import com.esotericsoftware.kryonet.Connection; //导入方法依赖的package包/类
@Override
public void handle(Connection connection, BuyFromShopPacket packet)
{
	ShopNpc shopNpc = (ShopNpc) playState.getObject(packet.getShopId());
	ShopItemWrapper itemWrapper = shopNpc.getItemWrapper(packet.getItemId());
	Character userCharacter = gameData.getUserCharacterByConnectionId(connection.getID());
	PlayerCharacter character = (PlayerCharacter) playState.getObject(userCharacter.getId());

	int itemCount = packet.getAmount();
	int singleItemPrice = itemWrapper.getPrice();
	int totalPrice = singleItemPrice * itemCount;
	int characterGold = character.getProperties().gold;
	if (totalPrice > characterGold)
		connection.sendTCP(PacketsMaker.makeUnacceptableOperationPacket("You don't have enough gold!"));
	else
	{
		handleGoldPart(connection, totalPrice, character);
		InventoryPosition position = new InventoryPosition(packet.getDesiredInventoryPage(),
				packet.getDesiredInventoryX(), packet.getDesiredInventoryY());
		handleItemPart(connection, itemWrapper, character, itemCount, position);
	}
}
 
开发者ID:MMORPG-Prototype,项目名称:MMORPG_Prototype,代码行数:23,代码来源:BuyFromShopPacketHandler.java

示例8: received

import com.esotericsoftware.kryonet.Connection; //导入方法依赖的package包/类
@Override
public void received(final Connection connection, final Object object) {
  if (object instanceof Size) {
    final Size size = (Size) object;
    final long tod = size.tod;
    final int msgs = size.messages;
    final Price price = new Price();
    for (int i = 0; i < msgs; i++) {
      price.tod = tod;
      price.iid = i;
      price.bid = 2;
      price.ask = 3;
      price.trd = 4;
      price.vol = 5;
      while (!connection.isIdle()) {
        // busy spin waiting for space in buffer
      }
      connection.sendTCP(price);
    }
  }
}
 
开发者ID:benalexau,项目名称:rpc-bench,代码行数:22,代码来源:BenchServer.java

示例9: connected

import com.esotericsoftware.kryonet.Connection; //导入方法依赖的package包/类
@Override
public void connected(Connection connection) {
	if(this.connection == null) { //Only one client is allowed to connect at a time - connection gets set to null when disconnected gets called.
		try {
			this.connection = connection;
			connection.sendTCP(SensorMessages.createStatusMessage("Connected to Endpoint. Sensor: " + sensor + ".Connection from " + connection));
		} catch (PortException e) {
			connection.close();
			e.printStackTrace();
			throw new RuntimeException("Sensor port already in use.");
		}
	}
}
 
开发者ID:Echtzeitsysteme,项目名称:mindroid,代码行数:14,代码来源:SensorEndpoint.java

示例10: handleGoldPart

import com.esotericsoftware.kryonet.Connection; //导入方法依赖的package包/类
private void handleGoldPart(Connection connection, int totalPrice, PlayerCharacter buyer)
{
	int characterGold = buyer.getProperties().gold;
	int goldAfterTrade = characterGold - totalPrice;
	buyer.setGold(goldAfterTrade);
	connection.sendTCP(PacketsMaker.makeGoldAmountChangePacket(goldAfterTrade));
}
 
开发者ID:MMORPG-Prototype,项目名称:MMORPG_Prototype,代码行数:8,代码来源:BuyFromShopPacketHandler.java

示例11: handleCreateSensorMessage

import com.esotericsoftware.kryonet.Connection; //导入方法依赖的package包/类
private void handleCreateSensorMessage(final Connection conn, final CreateSensorMessage msg) {
	Thread createSensor = new Thread(){
		@Override
		public void run(){
			LocalEV3.get().getLED().setPattern(6);
			
			if(sensPorts.containsKey(msg.getPort())){
				try {
					if(createSensorEndpoint( sensPorts.get(msg.getPort()),msg.getSensorType(),msg.getNetworkPort() )){
						conn.sendTCP(BrickMessages.createEndpointCreatedMessage(true, msg.getPort(), "Sensor endpoint created: "+msg.getPort(), true, false));		
					}else{
						isBlocked = true;
						System.out.println("System got blocked by handleCreateSensorMethod");
						conn.sendTCP(BrickMessages.createEndpointCreatedMessage(false, msg.getPort(), "Sensor endpoint not created: "+msg.getPort(), true, false));					
					}
				} catch (IOException e) {
					conn.sendTCP(BrickMessages.createEndpointCreatedMessage(false, msg.getPort(), "IOException: Sensor endpoint not created: "+msg.getPort(), true, false)+"\n "+e.toString());				
					e.printStackTrace();
				}
				
				
			}else{
				conn.sendTCP(SensorMessages.createSensorErrorMessage(null, "Port not found!"));
			}	
		}
	};
	
	creationThreads.add(createSensor);
	return;
}
 
开发者ID:Echtzeitsysteme,项目名称:mindroid,代码行数:31,代码来源:DeviceManager.java

示例12: handle

import com.esotericsoftware.kryonet.Connection; //导入方法依赖的package包/类
@Override
public void handle(Connection connection, OpenContainterPacket packet)
{
	if(playState.hasContainer(packet.gameX, packet.gameY))
	{
		GameContainer container = playState.getContainer(packet.gameX, packet.gameY);
		connection.sendTCP(PacketsMaker.makeOpenContainerPacket(container));
	}
	Log.info("OpenContainer packet received" + packet.gameX + " " + packet.gameY);
}
 
开发者ID:MMORPG-Prototype,项目名称:MMORPG_Prototype,代码行数:11,代码来源:OpenContainerPacketHandler.java

示例13: handle

import com.esotericsoftware.kryonet.Connection; //导入方法依赖的package包/类
@Override
public void handle(Connection connection, TakeItemFromContainerPacket packet)
{
	long characterId = gameData.getCharacterIdByConnectionId(connection.getID());
	PlayerCharacter player = (PlayerCharacter)playState.getObject(characterId);
	GameContainer container = playState.getContainer(packet.getContainerId());
	Item item = container.removeItem(packet.getItemId());
	server.sendToAllTCP(PacketsMaker.makeContainerItemRemovalPacket(packet.getContainerId(), packet.getItemId()));
	InventoryPosition desiredPosition = new InventoryPosition(packet.getDesiredInventoryPage(), packet.getDesiredInventoryX(), packet.getDesiredInventoryY());
	item.setInventoryPosition(desiredPosition);		
	player.addItemAllowStacking(item);
	connection.sendTCP(PacketsMaker.makeItemPacket(item));
}
 
开发者ID:MMORPG-Prototype,项目名称:MMORPG_Prototype,代码行数:14,代码来源:TakeItemFromContainerPacketHandler.java

示例14: handle

import com.esotericsoftware.kryonet.Connection; //导入方法依赖的package包/类
@Override
public void handle(Connection connection, InventoryItemRepositionRequestPacket packet)
{
	int characterId = gameData.getCharacterIdByConnectionId(connection.getID());
	InventoryRepositionableItemsOwner playerCharacter = (InventoryRepositionableItemsOwner) playState
			.getObject(characterId);
	Item item = playerCharacter.getItem(packet.getTargetItemId());
	InventoryPosition desiredPosition = new InventoryPosition(packet.getInventoryPageNumber(),
			packet.getInventoryPageX(), packet.getInventoryPageY());
	InventoryPosition sourcePosition = item.getInventoryPosition();
	Item itemInDestinationPosition = playerCharacter.getItem(desiredPosition);
	if (itemInDestinationPosition == null)
	{
		connection.sendTCP(
				PacketsMaker.makeInventoryItemRepositionPacket(sourcePosition, desiredPosition));
		item.setInventoryPosition(desiredPosition);
	} else if(itemInDestinationPosition instanceof StackableItem && 
			itemInDestinationPosition.getIdentifier().equals(item.getIdentifier()))
	{
		connection.sendTCP(PacketsMaker.makeInventoryItemStackPacket(sourcePosition, desiredPosition));
		((StackableItem)itemInDestinationPosition).stackWith((StackableItem)item);
		playerCharacter.removeItem(item.getId());
	}
	else
	{
		connection.sendTCP(PacketsMaker.makeInventoryItemSwapPacket(sourcePosition, desiredPosition));
		itemInDestinationPosition.setInventoryPosition(sourcePosition);;
		item.setInventoryPosition(desiredPosition);
	}
}
 
开发者ID:MMORPG-Prototype,项目名称:MMORPG_Prototype,代码行数:31,代码来源:InventoryItemRepositionRequestPacketHandler.java

示例15: handle

import com.esotericsoftware.kryonet.Connection; //导入方法依赖的package包/类
@Override
public void handle(Connection connection, AcceptQuestPacket packet)
{
    Character character = gameDataRetriever.getUserCharacterByConnectionId(connection.getID());
    Quest quest = questRepository.findByNameFetchItemsReward(packet.getQuestName());
    CharactersQuests characterQuest = new CharactersQuests(character, quest);
    character.getQuests().add(characterQuest);
    connection.sendTCP(PacketsMaker.makeQuestAcceptedPacket(characterQuest));
}
 
开发者ID:MMORPG-Prototype,项目名称:MMORPG_Prototype,代码行数:10,代码来源:AcceptQuestPacketHandler.java


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