Simple TCP gameplay (20 posts)

Topic tags: jME3, jmonkey, Multiplayer, mygame, networking, problem, spidermonkey
  • Profile picture of synok synok said 6 months, 3 weeks ago:

    Hello guys,

    Thanks for a great SDK! I am working on a voxel kind of project and my goal is to make it Multiplayer as that plays a big part in my game.

    So I tried creating a server using SpiderMonkey, I guess, with the following code;

    Server myServer = Network.createServer(6143);
                 myServer.start();

    But it would not compile, telling me about surrounding it with Try and Catch statements. So I did. Ended up with;

           try {
                Server myServer = Network.createServer(6143);
                 myServer.start();
            } catch (IOException ex) {
                Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
            }
       

    This compiled, so I tried creating a client, it it was the same story. I had to surround with Try and Catch like this;

    try {
                Client myClient = Network.connectToServer("90.129.144.158", 6143);
                myClient.start();
            } catch (IOException ex) {
                Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
            }

    After this I try running it and the console told me the connection was timed out. Is that because I am trying to join a TCP game where I am the host?
    If so, will it work if someone else plays the game, or did I miss a thing or two?

    The log from the console told me this;


    INFO: Kernel started for connection:0.0.0.0/0.0.0.0:6143.
    2011-okt-30 14:06:13 mygame.Main simpleInitApp
    SERIOUS: null
    java.net.ConnectException: Connection timed out: connect
    at java.net.PlainSocketImpl.socketConnect(Native Method)
    at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:333)
    at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:195)
    at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:182)
    at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:366)
    at java.net.Socket.connect(Socket.java:525)
    at java.net.Socket.connect(Socket.java:475)
    at java.net.Socket.(Socket.java:372)
    at java.net.Socket.(Socket.java:215)
    at com.jme3.network.kernel.tcp.SocketConnector.(SocketConnector.java:62)
    at com.jme3.network.Network.connectToServer(Network.java:166)
    at com.jme3.network.Network.connectToServer(Network.java:123)
    at mygame.Main.simpleInitApp(Main.java:62)
    at com.jme3.app.SimpleApplication.initialize(SimpleApplication.java:230)
    at com.jme3.system.lwjgl.LwjglAbstractDisplay.initInThread(LwjglAbstractDisplay.java:129)
    at com.jme3.system.lwjgl.LwjglAbstractDisplay.run(LwjglAbstractDisplay.java:205)
    at java.lang.Thread.run(Thread.java:619)

    What is up with the IP set to 0.0.0.0? Any help is appreciated.

    - Lars.

  • Profile picture of sbook sbook261p said 6 months, 3 weeks ago:

    You’re connecting to your external IP address which you likely aren’t getting access to because the port is blocked by your router. Try first connecting to “127.0.0.1″ (this is your computer).. Presuming that succeeds, you will want to look up the instructions on port forwarding for your particular router.

  • Profile picture of synok synok said 6 months, 3 weeks ago:

    I am using mobile internet, the one with a USB. So what is the setup of the IP on a TCP game? I guess I cannot use 127.0.0.1 as it is my localhost.

  • Profile picture of sbook sbook261p said 6 months, 3 weeks ago:

    My guess is that you aren’t going to be able to unblock ports using one of those mobile USB sticks. If you’re connecting a client to server on the same computer, 127.0.0.1 is fine.. If you were behind a router then you’d have DHCP assigned addresses for each device but your possibilities are really limited when you’re connected directly to the ISP.

  • Profile picture of synok synok said 6 months, 3 weeks ago:

    Think I got LAN working now, since it establishes a connection. But the other player in the LAN wont show up. Ideas?

  • Profile picture of sbook sbook261p said 6 months, 3 weeks ago:

    Unless I’m missing something your test case only shows a single client connecting to your server…

    From a second process (i.e: another java application), run another client:

    public static void main(String[] args){
            try {
                Client myClient = Network.connectToServer("TheIPAddressYouUsed", 6143);
                myClient.start();
            } catch (IOException ex) {
                Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
            }
    }
    
  • Profile picture of synok synok said 6 months, 3 weeks ago:

    Yeah, I might try that. I added a custom cube to the camera making it follow with target on the cube. So you control the cube and if I run from a second process as you say, the cube will be visible? I set up an ad-hoc network on my computer and have the game running on both computers in the network. My guess is that it connected successfully but we couldn’t see eachothers cubes that you control.

    Also, a bit off-topic. Can I log everything in the console to a text-file for debugging purposes? That case I can see that the connection was established between the computers.

  • Profile picture of sbook sbook261p said 6 months, 3 weeks ago:

    synok said:
    Yeah, I might try that. I added a custom cube to the camera making it follow with target on the cube. So you control the cube and if I run from a second process as you say, the cube will be visible? I set up an ad-hoc network on my computer and have the game running on both computers in the network. My guess is that it connected successfully but we couldn’t see eachothers cubes that you control.

    Have you followed the networking tutorial?

    synok said:
    Also, a bit off-topic. Can I log everything in the console to a text-file for debugging purposes? That case I can see that the connection was established between the computers.

    You want FileHandler.

    Used like:

    myLogger.addHandler(myFileHandler);
  • Profile picture of synok synok said 6 months, 3 weeks ago:

    Yep, I followed the tutorial as far as setting up a server and client goes. I presumed that was all I needed at the moment.

    Edit: Also regarding the different processes. When I make the server and client versions I comment away the functions to start the server and compile, which would give me the client. When I want to compile the server version, I comment away the functions to start a client.

  • Profile picture of pspeed pspeed815p said 6 months, 3 weeks ago:

    You can also look at the test chat server and test chat client in the JME tests.

    It’s a good idea to have separate paths through your code for client and server rather than recompiling to get to each one… that could be fraught with peril.

  • Profile picture of synok synok said 6 months, 3 weeks ago:

    I believe I tried anything now to get the other player into my game. Also I would be really happy if anyone could provide an example on a simple setup for a game server and client.

  • Profile picture of pspeed pspeed815p said 6 months, 3 weeks ago:

    synok said:
    I believe I tried anything now to get the other player into my game. Also I would be really happy if anyone could provide an example on a simple setup for a game server and client.

    There is TestChatServer and TestChatClient that supports any number of clients. Setting up a game server is no different… just the messages you send are different.

    Or for a more involved example you can look at MonkeyZone… but the others mentioned above are already in the SDK/JMP.

  • Profile picture of synok synok said 6 months, 3 weeks ago:

    I found another library called JGN. I guess I can try that.

  • Profile picture of normen normen1290p said 6 months, 3 weeks ago:

    :roll: Its not like JGN does anything else than the networking in jme3 does. You will always have to understand whats happening and write the code for your game.

  • Profile picture of pspeed pspeed815p said 6 months, 3 weeks ago:

    Yeah, and I’m trying to understand how what I provided didn’t answer the question.