Search in sources :

Example 1 with ClientMessenger

use of games.strategy.net.ClientMessenger in project triplea by triplea-game.

the class ChannelMessengerTest method testMultipleClients.

@Test
public void testMultipleClients() throws Exception {
    // set up the client and server
    // so that the client has 1 subscribor, and the server knows about it
    final RemoteName test = new RemoteName(IChannelBase.class, "test");
    final ChannelSubscribor client1Subscribor = new ChannelSubscribor();
    clientChannelMessenger.registerChannelSubscriber(client1Subscribor, test);
    assertHasChannel(test, unifiedMessengerHub);
    assertEquals(1, clientChannelMessenger.getUnifiedMessenger().getLocalEndPointCount(test));
    // add a new client
    final String mac = MacFinder.getHashedMacAddress();
    final ClientMessenger clientMessenger2 = new ClientMessenger("localhost", serverPort, "client2", mac);
    final ChannelMessenger client2 = new ChannelMessenger(new UnifiedMessenger(clientMessenger2));
    ((IChannelBase) client2.getChannelBroadcastor(test)).testString("a");
    assertCallCountIs(client1Subscribor, 1);
}
Also used : RemoteName(games.strategy.engine.message.RemoteName) IChannelSubscribor(games.strategy.engine.message.IChannelSubscribor) ChannelMessenger(games.strategy.engine.message.ChannelMessenger) ClientMessenger(games.strategy.net.ClientMessenger) Test(org.junit.jupiter.api.Test)

Example 2 with ClientMessenger

use of games.strategy.net.ClientMessenger in project triplea by triplea-game.

the class ChannelMessengerTest method setUp.

@BeforeEach
public void setUp() throws IOException {
    serverMessenger = new ServerMessenger("Server", 0);
    serverMessenger.setAcceptNewConnections(true);
    serverPort = serverMessenger.getLocalNode().getSocketAddress().getPort();
    final String mac = MacFinder.getHashedMacAddress();
    clientMessenger = new ClientMessenger("localhost", serverPort, "client1", mac);
    final UnifiedMessenger unifiedMessenger = new UnifiedMessenger(serverMessenger);
    unifiedMessengerHub = unifiedMessenger.getHub();
    serverChannelMessenger = new ChannelMessenger(unifiedMessenger);
    clientChannelMessenger = new ChannelMessenger(new UnifiedMessenger(clientMessenger));
}
Also used : ServerMessenger(games.strategy.net.ServerMessenger) IServerMessenger(games.strategy.net.IServerMessenger) ChannelMessenger(games.strategy.engine.message.ChannelMessenger) ClientMessenger(games.strategy.net.ClientMessenger) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 3 with ClientMessenger

use of games.strategy.net.ClientMessenger in project triplea by triplea-game.

the class RemoteMessengerTest method testRemoteCall2.

@Test
public void testRemoteCall2() throws Exception {
    final RemoteName test = new RemoteName(ITestRemote.class, "test");
    ServerMessenger server = null;
    ClientMessenger client = null;
    try {
        server = new ServerMessenger("server", 0);
        server.setAcceptNewConnections(true);
        final int serverPort = server.getLocalNode().getSocketAddress().getPort();
        final String mac = MacFinder.getHashedMacAddress();
        client = new ClientMessenger("localhost", serverPort, "client", mac);
        final RemoteMessenger serverRemoteMessenger = new RemoteMessenger(new UnifiedMessenger(server));
        final TestRemote testRemote = new TestRemote();
        serverRemoteMessenger.registerRemote(testRemote, test);
        final RemoteMessenger clientRemoteMessenger = new RemoteMessenger(new UnifiedMessenger(client));
        // call it on the client
        // should be no need to wait since the constructor should not
        // reutrn until the initial state of the messenger is good
        final int incrementedValue = ((ITestRemote) clientRemoteMessenger.getRemote(test)).increment(1);
        assertEquals(2, incrementedValue);
        assertEquals(testRemote.getLastSenderNode(), client.getLocalNode());
    } finally {
        shutdownServerAndClient(server, client);
    }
}
Also used : RemoteName(games.strategy.engine.message.RemoteName) RemoteMessenger(games.strategy.engine.message.RemoteMessenger) ServerMessenger(games.strategy.net.ServerMessenger) IServerMessenger(games.strategy.net.IServerMessenger) ClientMessenger(games.strategy.net.ClientMessenger) Test(org.junit.jupiter.api.Test)

Example 4 with ClientMessenger

use of games.strategy.net.ClientMessenger in project triplea by triplea-game.

the class RemoteMessengerTest method testShutDownClient.

@Test
public void testShutDownClient() throws Exception {
    // when the client shutdown, remotes created
    // on the client should not be visible on server
    final RemoteName test = new RemoteName(ITestRemote.class, "test");
    ServerMessenger server = null;
    ClientMessenger client = null;
    try {
        server = new ServerMessenger("server", 0);
        server.setAcceptNewConnections(true);
        final int serverPort = server.getLocalNode().getSocketAddress().getPort();
        final String mac = MacFinder.getHashedMacAddress();
        client = new ClientMessenger("localhost", serverPort, "client", mac);
        final UnifiedMessenger serverUnifiedMessenger = new UnifiedMessenger(server);
        final RemoteMessenger clientRemoteMessenger = new RemoteMessenger(new UnifiedMessenger(client));
        clientRemoteMessenger.registerRemote(new TestRemote(), test);
        serverUnifiedMessenger.getHub().waitForNodesToImplement(test.getName());
        assertTrue(serverUnifiedMessenger.getHub().hasImplementors(test.getName()));
        client.shutDown();
        Interruptibles.sleep(200);
        assertTrue(!serverUnifiedMessenger.getHub().hasImplementors(test.getName()));
    } finally {
        shutdownServerAndClient(server, client);
    }
}
Also used : RemoteName(games.strategy.engine.message.RemoteName) RemoteMessenger(games.strategy.engine.message.RemoteMessenger) ServerMessenger(games.strategy.net.ServerMessenger) IServerMessenger(games.strategy.net.IServerMessenger) ClientMessenger(games.strategy.net.ClientMessenger) Test(org.junit.jupiter.api.Test)

Example 5 with ClientMessenger

use of games.strategy.net.ClientMessenger in project triplea by triplea-game.

the class RemoteMessengerTest method testRemoteCall.

@Test
public void testRemoteCall() throws Exception {
    final RemoteName test = new RemoteName(ITestRemote.class, "test");
    ServerMessenger server = null;
    ClientMessenger client = null;
    try {
        server = new ServerMessenger("server", 0);
        server.setAcceptNewConnections(true);
        final int serverPort = server.getLocalNode().getSocketAddress().getPort();
        final String mac = MacFinder.getHashedMacAddress();
        client = new ClientMessenger("localhost", serverPort, "client", mac);
        final UnifiedMessenger serverUnifiedMessenger = new UnifiedMessenger(server);
        unifiedMessengerHub = serverUnifiedMessenger.getHub();
        final RemoteMessenger serverRemoteMessenger = new RemoteMessenger(serverUnifiedMessenger);
        final RemoteMessenger clientRemoteMessenger = new RemoteMessenger(new UnifiedMessenger(client));
        // register it on the server
        final TestRemote testRemote = new TestRemote();
        serverRemoteMessenger.registerRemote(testRemote, test);
        // since the registration must go over a socket
        // and through a couple threads, wait for the
        // client to get it
        int waitCount = 0;
        while (!unifiedMessengerHub.hasImplementors(test.getName()) && waitCount < 20) {
            waitCount++;
            Interruptibles.sleep(50);
        }
        // call it on the client
        final int incrementedValue = ((ITestRemote) clientRemoteMessenger.getRemote(test)).increment(1);
        assertEquals(2, incrementedValue);
        assertEquals(testRemote.getLastSenderNode(), client.getLocalNode());
    } finally {
        shutdownServerAndClient(server, client);
    }
}
Also used : RemoteName(games.strategy.engine.message.RemoteName) RemoteMessenger(games.strategy.engine.message.RemoteMessenger) ServerMessenger(games.strategy.net.ServerMessenger) IServerMessenger(games.strategy.net.IServerMessenger) ClientMessenger(games.strategy.net.ClientMessenger) Test(org.junit.jupiter.api.Test)

Aggregations

ClientMessenger (games.strategy.net.ClientMessenger)10 IServerMessenger (games.strategy.net.IServerMessenger)8 RemoteMessenger (games.strategy.engine.message.RemoteMessenger)7 ServerMessenger (games.strategy.net.ServerMessenger)7 ChannelMessenger (games.strategy.engine.message.ChannelMessenger)5 RemoteName (games.strategy.engine.message.RemoteName)5 Test (org.junit.jupiter.api.Test)5 UnifiedMessenger (games.strategy.engine.message.unifiedmessenger.UnifiedMessenger)4 IRemoteMessenger (games.strategy.engine.message.IRemoteMessenger)3 BeforeEach (org.junit.jupiter.api.BeforeEach)3 IChannelMessenger (games.strategy.engine.message.IChannelMessenger)2 ClientLogger (games.strategy.debug.ClientLogger)1 ClientContext (games.strategy.engine.ClientContext)1 ChatPanel (games.strategy.engine.chat.ChatPanel)1 IChatPanel (games.strategy.engine.chat.IChatPanel)1 GameStepListener (games.strategy.engine.data.events.GameStepListener)1 LOBBY_GAME_COMMENTS (games.strategy.engine.framework.CliProperties.LOBBY_GAME_COMMENTS)1 LOBBY_GAME_HOSTED_BY (games.strategy.engine.framework.CliProperties.LOBBY_GAME_HOSTED_BY)1 LOBBY_HOST (games.strategy.engine.framework.CliProperties.LOBBY_HOST)1 LOBBY_PORT (games.strategy.engine.framework.CliProperties.LOBBY_PORT)1