Java Code Examples for com.esotericsoftware.kryonet.Server#addListener()

The following examples show how to use com.esotericsoftware.kryonet.Server#addListener() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: LobbyScreen.java    From killingspree with MIT License 5 votes vote down vote up
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();
    }
 
Example 2
Source File: NetServer.java    From gdx-proto with Apache License 2.0 5 votes vote down vote up
public NetServer() {
	clientMap = new ObjectMap<>();
	server = new Server(NetManager.writeBufferSize, NetManager.objectBufferSize);
	NetManager.registerKryoClasses(server.getKryo());
	try {
		server.bind(NetManager.tcpPort, NetManager.udpPort);
		server.start();
		server.addListener(createListener(simulateLag));
		Log.debug("server is listening at: " + NetManager.host + ":" + NetManager.tcpPort);
	} catch (IOException e) {
		Log.error(e.toString());
		throw new GdxRuntimeException(e);
	}
}
 
Example 3
Source File: WorldManager.java    From killingspree with MIT License 4 votes vote down vote up
public WorldManager(final Server server){
        i = 0;
        
        playerPositions = new ArrayList<Vector2>();
        playerPositions.add(new Vector2(50,85));
        playerPositions.add(new Vector2(395,85));
        playerPositions.add(new Vector2(50,230));
        playerPositions.add(new Vector2(395,230));
        
        playerList = new ConcurrentHashMap<Integer, ServerPlayer>();
        
        world = new World(new Vector2(0, -500f));
        
        serverListener = new WorldManagerServerListener();

        if  (server != null) {
            server.addListener(serverListener);
        }
        
        this.server = server;
        
        entities = new ArrayList<ServerEntity>();
        
        incomingEventQueue = new ArrayList<Event>();
        outgoingEventQueue = new ArrayList<Event>();
        dummyConnection = new MyConnection();
        incomingEventQueue.add(MessageObjectPool.instance.
                eventPool.obtain().set(State.CONNECTED, null));
        outgoingEventQueue.add(MessageObjectPool.instance.
                eventPool.obtain().set(State.CONNECTED, null));
        audio = new AudioMessage();

        worldBodyUtils = new WorldBodyUtils(worldManager);

        id = 0;
//        frog = new ServerFrog(id++, 20, 100, worldBodyUtils);
//        entities.add(frog);
//        fly = new ServerFly(id++, 20, 100, worldBodyUtils);
//        entities.add(fly);
//        blob = new ServerBlob(id++, 20, 100, worldBodyUtils);
//        entities.add(blob);
        if (server == null)
            loader = new LevelLoader("maps/retro-small.txt", this);
    }