當前位置: 首頁>>代碼示例>>Java>>正文


Java Connection類代碼示例

本文整理匯總了Java中com.esotericsoftware.kryonet.Connection的典型用法代碼示例。如果您正苦於以下問題:Java Connection類的具體用法?Java Connection怎麽用?Java Connection使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


Connection類屬於com.esotericsoftware.kryonet包,在下文中一共展示了Connection類的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: getRandomGame

import com.esotericsoftware.kryonet.Connection; //導入依賴的package包/類
private GameResponse getRandomGame(Connection connection, Account account) {
    Game randomGame = null;
    // Go through the games
    if (gamesMap != null) {
        for (Game game : gamesMap.values()) {
            // If there's a game currently waiting for more players, that's the one to return
            if (!game.isInProgress() && game.getPlayerCount() < Config.MAX_PLAYERS) {
                // Add the player to the game
                game.addPlayer(account, connection.getID());
                gamesMap.put(account.getUsername(), game);
                randomGame = game;
            }
        }
    }
    return GameResponse.newInstance(randomGame);
}
 
開發者ID:teobaranga,項目名稱:Catan,代碼行數:17,代碼來源:CatanServer.java

示例3: LoginScreen

import com.esotericsoftware.kryonet.Connection; //導入依賴的package包/類
public LoginScreen(CatanGame pGame) {
    aGame = pGame;
    listener = new Listener() {
        @Override
        public void received(Connection connection, Object object) {
            if (object instanceof LoginResponse) {
                Gdx.app.postRunnable(() -> {
                    // Handle the login response from the server
                    if (((LoginResponse) object).success) {
                        // Cache the account used to login successfully
                        AccountManager.writeLocalAccount(account);
                        CatanGame.account = account;
                        // Move on to the main screen
                        aGame.switchScreen(ScreenKind.MAIN_MENU);
                    } else {
                        errorMessageLabel.setText(ERROR_USERNAME);
                    }
                });
            }
        }
    };
}
 
開發者ID:teobaranga,項目名稱:Catan,代碼行數:23,代碼來源:LoginScreen.java

示例4: 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

示例5: received

import com.esotericsoftware.kryonet.Connection; //導入依賴的package包/類
@Override
  public void received(Connection connection, Object object){
/** Message if the Endpoint-creation was successful or not **/
  	System.out.println("Local-EV3MotorManager: received a message!");
  	
if(object.getClass() == BrickMessages.EndpointCreatedMessage.class){
	BrickMessages.EndpointCreatedMessage ecmsg = (BrickMessages.EndpointCreatedMessage)object;
	System.out.println("Local-EV3MotorManager: Received a EndpointCreatedMessage! -> "+ecmsg.toString());
	if(ecmsg.isMotor()){
		if(ecmsg.isSuccess()){
			System.out.println("Local-EV3MotorManager: isSuccess at port "+ecmsg.getPort()+"#");
			if(motors.containsKey(EV3MotorPort.getPort(ecmsg.getPort()))){
				System.out.println("Local-EV3MotorManager: Endpoint creation successfull - connect to endpoint!");
				endpoints.get(EV3MotorPort.getPort(ecmsg.getPort())).connect();
			}else{
				System.out.println("Local-EV3MotorManager: Sensor does not exist");
			}
		}else{
			//TODO Tell Sensor/Motor Manager that endpoint creation failed
		}
	}
}
  }
 
開發者ID:Echtzeitsysteme,項目名稱:mindroid,代碼行數:24,代碼來源:EV3MotorManager.java

示例6: received

import com.esotericsoftware.kryonet.Connection; //導入依賴的package包/類
@Override
public void received(Connection connection, Object object) {
	System.out.println("Local-EV3Display: Received Message "+object.toString());
	if(object.getClass() == BrickMessages.EndpointCreatedMessage.class){
		BrickMessages.EndpointCreatedMessage msg = (EndpointCreatedMessage) object;
		if(!msg.isMotor() && !msg.isSensor()){
			if(msg.isSuccess() && msg.getMsg().equals("DISPLAY")){
				connect();
				System.out.println("EV3-Display: connecting to endpoint!");
			}
		}
		return;
	}
	
	if(object.getClass() == DisplayMessages.HelloDisplay.class){
		ready = true;
	}
	
}
 
開發者ID:Echtzeitsysteme,項目名稱:mindroid,代碼行數:20,代碼來源:EV3Display.java

示例7: show

import com.esotericsoftware.kryonet.Connection; //導入依賴的package包/類
@Override
public void show() {
    super.show();

    entities = new HashMap<Integer, EntityPacket.EntityRender>();

    game.getClient().sendTCP(new ViewShare("696969"));

    game.getClient().addListener(new Listener() {
        @Override
        public void received(Connection connection, Object o) {
            if(o instanceof EntityPacket)
                Gdx.app.log("Entities", "Session" + ((EntityPacket) o).session);
        }
    });
}
 
開發者ID:justinmarentette11,項目名稱:Tower-Defense-Galaxy,代碼行數:17,代碼來源:SpectateScreen.java

示例8: addReceiver

import com.esotericsoftware.kryonet.Connection; //導入依賴的package包/類
/**
 * Makes this chat client process and respond to audio sent from the server. If this message is not called, you will not hear anything
 * from the server!
 * @param client The client that audio data will be sent to from the server. Just use the normal client.
 */
public void addReceiver(Client client){
	
	if(this.player == null)
		this.createPlayer();
	
	client.addListener(new Listener(){
		public void received(Connection connection, Object object) {
			
			// Only read objects of the correct type.
			if(object instanceof VoiceNetData){
				
				// Read data
				VoiceNetData message = (VoiceNetData)object;					
				short[] data = message.getData();
				
				// Play audio
				processAudio(data, connection, message);
			}
		}			
	});
}
 
開發者ID:Epicguru,項目名稱:VoiceChat,代碼行數:27,代碼來源:VoiceChatClient.java

示例9: 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

示例10: handle

import com.esotericsoftware.kryonet.Connection; //導入依賴的package包/類
@Override
public void handle(Connection connection, RetrieveGoldRewardPacket packet)
{
    Character character = gameDataRetriever.getUserCharacterByConnectionId(connection.getID());
    CharactersQuests quest = findSuiteQuest(character.getQuests(), packet.getQuestName());
    int goldReward = quest.getGoldReward();
    if (goldReward > 0)
    {
        quest.setGoldReward(0);
        character.setGold(character.getGold() + goldReward);
        packetsSender.sendTo(connection.getID(), PacketsMaker.makeGoldReceivePacket(goldReward));
        packetsSender.sendTo(connection.getID(),
                PacketsMaker.makeQuestRewardGoldRemovalPacket(goldReward));
    } else
        packetsSender.sendTo(connection.getID(),
                PacketsMaker.makeUnacceptableOperationPacket("There is no gold left!"));

}
 
開發者ID:MMORPG-Prototype,項目名稱:MMORPG_Prototype,代碼行數:19,代碼來源:RetrieveGoldRewardPacketHandler.java

示例11: clientBoardClickProperHandle

import com.esotericsoftware.kryonet.Connection; //導入依賴的package包/類
private void clientBoardClickProperHandle(Connection connection, GameObject target, PlayerCharacter source)
{
	// TODO: refactor, implement collicion detection on clent side, so he 
	// can tell what he wants to do directly
	if (target instanceof ShopNpc)
		sendShopItemsInfo(connection, (ShopNpc) target);
	else if (target instanceof QuestDialogNpc)
		propagateQuestDialogEvent((QuestDialogNpc) target, source);
	else if (target instanceof Monster)
		tryToTargetMonster(connection, (Monster) target, source);
	else if (target instanceof QuestBoard)
		sendQuestBoardInfo(connection, (QuestBoard) target);
	else if (target.getClass().getSimpleName().contains("NullGameObject"))
		;//ignore
	else
		throw new NotImplementedException("Not implemented");

}
 
開發者ID:MMORPG-Prototype,項目名稱:MMORPG_Prototype,代碼行數:19,代碼來源:CharacterBoardClickPacketHandler.java

示例12: 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

示例13: 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

示例14: 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

示例15: handle

import com.esotericsoftware.kryonet.Connection; //導入依賴的package包/類
@Override
public void handle(Connection connection, ChatMessagePacket packet)
{
	Field connectionsField = FieldUtils.getField(Server.class, "connections", true);
	
	Connection[] connections;
	try
	{
		connections = (Connection[])FieldUtils.readField(connectionsField, server, true);
	} catch (IllegalAccessException e)
	{
		throw new RuntimeException(e);
	}
	ChatMessageReplyPacket newPacket = new ChatMessageReplyPacket();
	Character sender = gameData.getUserCharacterByConnectionId(connection.getID());
	String nickname = sender.getNickname();
	newPacket.setMessage(packet.getMessage());
	newPacket.setNickname(nickname);
	Character character;
	for(Connection client : connections)		
		if((character = gameData.getUserCharacterByConnectionId(client.getID())) != null)
		{
			newPacket.setSourceCharacterId(character.getId());
			server.sendToTCP(client.getID(), newPacket);
		}
}
 
開發者ID:MMORPG-Prototype,項目名稱:MMORPG_Prototype,代碼行數:27,代碼來源:ChatMessagePacketHandler.java


注:本文中的com.esotericsoftware.kryonet.Connection類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。