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


Java Client.connect方法代碼示例

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


在下文中一共展示了Client.connect方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: ClientNetworkController

import com.esotericsoftware.kryonet.Client; //導入方法依賴的package包/類
public ClientNetworkController() {
	while (true) {
		promptIPPort();
		client = new Client();
		client.start();
		try {
			client.connect(5000, Variables.serverIP, Variables.port);
		}
		catch (IOException e) {
			Utilities.popupMessage("BuildStation", "Invalid Input\nThe server refused the connection or an unknown error occurred.");
			e.printStackTrace();
			promptIPPort();
			continue;
		}
		client.getKryo().setRegistrationRequired(false);
		ListenerList.addListeners(client);
		break;
	}
}
 
開發者ID:Ameliorate,項目名稱:Buildstation-3,代碼行數:20,代碼來源:ClientNetworkController.java

示例2: loadLevel

import com.esotericsoftware.kryonet.Client; //導入方法依賴的package包/類
public boolean loadLevel(String level, String host, String name) {
    if (isServer) {
        world = new WorldManager(server);
        if (server == null)
            world.loader.platformServices = game.platformServices;
    } else {
        client = new Client();
        NetworkRegisterer.register(client);
        client.start();
        try {
            client.connect(Constants.TIMEOUT, host,
                    Constants.GAME_TCP_PORT,
                    Constants.GAME_UDP_PORT);
        } catch (IOException e) {
            game.platformServices.toast("Server not found");
            e.printStackTrace();
            game.setScreen(new ClientDiscoveryScreen(game));
            return false;
        }
    }
    
    renderer = new WorldRenderer(world, client, game);
    renderer.loadLevel(level, isServer, name);
    return true;
}
 
開發者ID:ganeshkamathp,項目名稱:killingspree,代碼行數:26,代碼來源:GameScreen.java

示例3: launchClient

import com.esotericsoftware.kryonet.Client; //導入方法依賴的package包/類
@Override
public synchronized boolean launchClient()
{	boolean result = true;

	client = new Client(60000, 60000);
	client.start();

	firstRound = true;

	ClassRegisterer.register(client);

	client.addListener(this);

	int timeout = 5000;
	try
	{	client.connect(timeout, ip, port, port + 1);
	}
	catch (IOException e)
	{	result = false;
		e.printStackTrace();
	}

	return result;
}
 
開發者ID:CeriAvignon,項目名稱:Projet2015,代碼行數:25,代碼來源:ClientCommunicationKryonetImpl.java

示例4: tryConnecting

import com.esotericsoftware.kryonet.Client; //導入方法依賴的package包/類
private void tryConnecting(Client client, ConnectionInfo connectionInfo)
{
	try
	{
		client.connect(3000, connectionInfo.getIp(), connectionInfo.getTcpPort(), connectionInfo.getUdpPort());
	} catch (IOException e)
	{
		currentTryout++;
		if (currentTryout < maxTryouts)
			tryConnecting(client, connectionInfo);
	}

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

示例5: initNetwork

import com.esotericsoftware.kryonet.Client; //導入方法依賴的package包/類
public void initNetwork() {
    client = new Client(Network.BUFFER_SIZE, Network.BUFFER_SIZE);

    Initializer.registerClasses(client.getKryo());
    client.addListener(this);
    clientThread = new Thread(client);
    clientThread.start();
    try {
        client.connect(5000, address, port);
    } catch (IOException e) {
        e.printStackTrace();
    }
}
 
開發者ID:cthit,項目名稱:CodeIT,代碼行數:14,代碼來源:RatingVisualizerController.java

示例6: HeadlessClientNetworkController

import com.esotericsoftware.kryonet.Client; //導入方法依賴的package包/類
/**
 * @throws IOException If the server refused the connection.
 */
public HeadlessClientNetworkController() throws IOException {
	client = new Client();
	client.start();
	client.connect(5000, Variables.serverIP, Variables.port);
	client.getKryo().setRegistrationRequired(false);
	ListenerList.addListeners(client);
	isHeadless = true;	// I wish I could avoid this, but for some reason, I can't override promptIPPort.
}
 
開發者ID:Ameliorate,項目名稱:Buildstation-3,代碼行數:12,代碼來源:HeadlessClientNetworkController.java

示例7: setServer

import com.esotericsoftware.kryonet.Client; //導入方法依賴的package包/類
public void setServer(boolean isServer) {
        this.isServer = isServer;
        try {
            if (isServer) {
                server = new Server();
                NetworkRegisterer.register(server);
                serverListener = new LobbyServerListener();
                server.addListener(serverListener);
                server.start();
                server.bind(Constants.DISCOVERY_TCP_PORT,
                            Constants.DISCOVERY_UDP_PORT);
//                Thread.currentThread().sleep(200);
            }
            
            client = new Client();
            NetworkRegisterer.register(client);
            client.start();
            clientListener = new LobbyClientListener();
            client.addListener(clientListener);
            client.connect(5000, host, 
                    Constants.DISCOVERY_TCP_PORT,
                    Constants.DISCOVERY_UDP_PORT);
        } catch (Exception e) {
            currentButton = backButton;
            markForDispose = true;
            e.printStackTrace();
        }
        addAllButtons();
    }
 
開發者ID:ganeshkamathp,項目名稱:killingspree,代碼行數:30,代碼來源:LobbyScreen.java

示例8: CalendarClient

import com.esotericsoftware.kryonet.Client; //導入方法依賴的package包/類
protected CalendarClient() {
    client = new Client(128000, 6000);
    client.start();

    Network.register(client);

    client.addListener(new FrontendListener(client));

    try {
        client.connect(TIMEOUT, "", Network.PORT);
    } catch (IOException e) {
        e.printStackTrace();
        System.exit(1);
    }
}
 
開發者ID:Fellesprosjekt-27,項目名稱:fellesprosjekt,代碼行數:16,代碼來源:CalendarClient.java

示例9: initSocket

import com.esotericsoftware.kryonet.Client; //導入方法依賴的package包/類
private void initSocket (String serverIp, int port) throws IOException {
	if (InetAddressValidator.getInstance().isValidInet4Address(serverIp) == false) {
		InetAddress address = InetAddress.getByName(serverIp);
		serverIp = address.getHostAddress();
	}

	client = new Client(200000, 200000);
	KryoUtils.registerNetClasses(client.getKryo());
	client.start();

	sender = new ExchangeSender("Client Sender", client);
	pinger = new ExchangePinger(sender, "Client Pinger", new TimeoutListener() {
		@Override
		public void timedOut () {
			postStatus(ConnectionStatus.TIMEDOUT, "Server not responded to ping messages.");
			disconnect(false);
		}
	});

	client.connect(5000, serverIp, port);
	client.addListener(new Listener() {
		@Override
		public void received (Connection connection, Object object) {
			if (object instanceof Exchange) {
				Exchange exchange = (Exchange)object;
				processLater(exchange);
			}
		}
	});
}
 
開發者ID:kotcrab,項目名稱:arget,代碼行數:31,代碼來源:ArgetClient.java

示例10: establishClient

import com.esotericsoftware.kryonet.Client; //導入方法依賴的package包/類
private Client establishClient(String host, int port, int timeout) throws IOException{
	Client lClient = new Client();
	lClient.addListener(listener);
	
	Network.registerClasses(lClient.getKryo());
	
	lClient.addListener(clientListener);
	lClient.start();
	lClient.connect(timeout, host, port);
	
	return lClient;
}
 
開發者ID:rainu,項目名稱:ClipSync,代碼行數:13,代碼來源:CSClient.java

示例11: joinServer

import com.esotericsoftware.kryonet.Client; //導入方法依賴的package包/類
/**
 * Joins the server (by connection).
 * 
 * @param ip
 *            ip to be joined with.
 * @param port
 *            port to use when joining.
 * @param connectionTimeout
 *            if this timeout runs out while attempting to connect, you will
 *            disconnect.
 */
public void joinServer(String ip, int port, int connectionTimeout) {
	// Connecting with the client
	client = new Client();
	AppUtil.endpoint = client;
	client.addListener(new ClientListener());
	client.start();
	try {
		registerClasses(client.getKryo());
		client.connect(connectionTimeout, ip, port);
	} catch (IOException e) {
		e.printStackTrace();
		return;
	}
}
 
開發者ID:Teascade,項目名稱:Shadow-of-Goritur,代碼行數:26,代碼來源:SOGClient.java

示例12: shouldSendFromClient

import com.esotericsoftware.kryonet.Client; //導入方法依賴的package包/類
@Test
public void shouldSendFromClient() throws Exception {
    Thread.sleep(100);
    Client client = new Client();
    client.start();
    client.connect(5000, "localhost", PORT);
    client.sendTCP("WRITE[[0x0001:2:0x5050][0xFF00:2:0x10]]");
    client.close();
    Thread.sleep(200);
    //
    assertEquals(1, messages.size());
    assertEquals("[WRITE[[0x0001:2:0x5050][0xFF00:2:0x10]]]", messages.toString());
}
 
開發者ID:RBernhardt,項目名稱:homecockpit-fsuipc,代碼行數:14,代碼來源:KryoNetServerIntegrationTest.java

示例13: RemoteMinecraft

import com.esotericsoftware.kryonet.Client; //導入方法依賴的package包/類
public RemoteMinecraft(String address) {
	client = new Client(65536, 65536);
	Kryo kryo = client.getKryo();
	kryo.register(NetCreateWorldRequest.class);
	kryo.register(NetGetBiomeDataRequest.class);
	kryo.register(NetGetBiomeDataResult.class);
	kryo.register(NetBiome.class);
	kryo.register(NetBiome[].class);
	kryo.register(NetInfoRequest.class);
	kryo.register(int[].class);
	
	client.addListener(new Listener() {
		@Override
		public void received(Connection connection, Object object) {
			if (object instanceof NetGetBiomeDataResult) {
				currentResults = (NetGetBiomeDataResult)object;
				//Log.i("Received NetGetBiomeDataResult: " + currentResults);
			} else if (object instanceof NetBiome[]) {
				NetBiome[] biomes = (NetBiome[])object;
				for (int i = 0; i < biomes.length; i++) {
					if (biomes[i] != null) {
						new Biome(biomes[i].name, biomes[i].id, biomes[i].color | 0xFF000000, true);
					}
				}
			}
		}
	});
	
	client.start();
	try {
		client.connect(5000, address, 54580, 54580);
	} catch (IOException e) {
		e.printStackTrace();
	}
	
	client.sendTCP(new NetInfoRequest());
	
}
 
開發者ID:skiphs,項目名稱:AMIDST,代碼行數:39,代碼來源:RemoteMinecraft.java

示例14: connect

import com.esotericsoftware.kryonet.Client; //導入方法依賴的package包/類
/**
 * Connects a client asynchronously. After it is finished the appropriate
 * {@linkplain IClientCallback#onClientStarted(IOException) callback method}
 * is invoked.
 * 
 * @param ip
 *            The server's ip.
 * @param port
 *            The server's port.
 * @param callback
 *            The callback.
 */
public void connect(String ip, int port, IClientCallback callback) {
	client = new Client();
	client.start();

	NetworkRegisterer.registerClasses(client.getKryo());

	TypeListener listener = new TypeListener();
	listener.addTypeHandler(GameSetupMessage.class, (con, msg) -> {
		Gdx.app.log("Client",
				"Lobby beigetreten (ID: " + msg.getId() + ")");
		session.init(msg.getPlayers(), msg.getId(), msg.getSettings());
	});
	listener.addTypeHandler(ChatMessageSentMessage.class, (con, msg) -> {
		if (eventHandler != null)
			eventHandler.onNewChatMessage(msg.getSenderId(),
					msg.getMessage());
	});
	listener.addTypeHandler(PlayerChangedMessage.class, (con, msg) -> {
		session.getPlayers().put(msg.getId(), msg.getPlayer());

		if (eventHandler != null)
			eventHandler.onPlayerChanged();
	});
	listener.addTypeHandler(PlayerJoinedMessage.class, (con, msg) -> {
		session.getPlayers().put(msg.getId(), msg.getPlayer());

		if (eventHandler != null)
			eventHandler.onPlayerConnect(msg.getPlayer());
	});
	listener.addTypeHandler(PlayerLeftMessage.class, (con, msg) -> {
		Player p = session.getPlayers().get(msg.getId());
		session.getPlayers().remove(msg.getId());

		if (eventHandler != null)
			eventHandler.onPlayerDisconnect(p);
	});
	listener.addTypeHandler(SeverTurnMessage.class, (con, msg) -> {
		System.out.println("[Client] Server turn message received for turn " + msg.getTurn());
		session.addNewCommands(msg.getTurn(), msg.getPlayerCommands());
	});

	client.addListener(listener);

	Thread t = new Thread(new Runnable() {
		public void run() {
			try {
				client.connect(6000, ip, port);
			} catch (IOException e) {
				ex = e;
				e.printStackTrace();
			}
			Gdx.app.postRunnable(new Runnable() {
				@Override
				public void run() {
					callback.onClientConnected(ex);
				}
			});
		}
	});
	t.start();
}
 
開發者ID:eskalon,項目名稱:ProjektGG,代碼行數:74,代碼來源:ClientNetworkHandler.java

示例15: doInBackground

import com.esotericsoftware.kryonet.Client; //導入方法依賴的package包/類
@Override
protected Void doInBackground() throws Exception {
    final int BUFFER_SIZE = 10000;
    Client client = new Client(BUFFER_SIZE, BUFFER_SIZE);

    client.getKryo().register(PacketLogin.class);
    client.getKryo().register(PacketLoginResponse.class);
    client.getKryo().register(PacketRequestCaptcha.class);
    client.getKryo().register(PacketCaptchaImage.class);
    client.getKryo().register(byte[].class);
    client.getKryo().register(PacketRegister.class);
    client.getKryo().register(PacketRegistered.class);
    client.getKryo().register(PacketFilesListRequest.class);
    client.getKryo().register(PacketFilesList.class);
    client.getKryo().register(String[].class);


    client.addListener(new Listener() {
        @Override
        public void received(Connection connection, Object object) {
            if (object instanceof PacketFilesList) {
                PacketFilesList response = (PacketFilesList) object;
                System.out.println("[Sync] Got files: " + response.numFiles + " | " + response.files);

                publish(new FilesListState(response));

                connection.close();
            }
        }
    });

    client.start();

    try {
        client.connect(5000, Constants.SERVER_HOST, Constants.SERVER_PORT);
    } catch (Exception e) {
        e.printStackTrace();

        return null;
    }

    Thread.sleep(1000);
    PacketFilesListRequest req = new PacketFilesListRequest();
    req.clientPrefix = this.prefix;
    
    client.sendTCP(req);


    return null;
}
 
開發者ID:Cr0s,項目名稱:Kubach,代碼行數:51,代碼來源:RequestFilesListWorker.java


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