Hi !
Featured games (90)
games approved by the League of Dukes
Games in Showcase (683)
Games in Android Showcase (196)
games submitted by our members
Games in WIP (750)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Problems with online multi-player  (Read 2108 times)
0 Members and 1 Guest are viewing this topic.
Offline doby162

Senior Newbie

« Posted 2010-12-02 16:55:16 »

Greetings, people of the javaGaming forum! I am new here as I have been using  different forum, but they were unable to answer this question so I came here. I am a hobbyist Java game writer and I just added online multiplayer to my most recent game, Anaconda other A, which is like snake only with a lot more game modes. When I first wrote it I thought the difficult part would be establishing a connection between two computers, and so after I had written the code that allowed two Java programs to communicate, I immediately checked if it still worked on other computers and across networks. It did, without any changes required, so I went on to finish the game without conducting frequent checks to see if it still worked on multiple computers.

        Now I have finished it, and when I run it on my computer, it works like a charm (actuly better since charms don't work  Tongue ) but when I run it on two different computers, the client crashes the moment the games starts.  Cry I am using sockets, and will post the code if requested, but seeing as it's like 900 lines long I think I won't unless you want me to. I have yet to test it on many different computers, and on the few I have tested I have noticed that some will refuse entirely to host a game, while others will only host games and wont be a client. I tried disabling my firewall, but it changed nothing, I tried reading the error messages, but they were all "unidentified" and pertains mostly to the graphics portion of the software, making vague references to the AWT thread. they were also were long and seemed to change a little each time.   Huh

        Any and all help is appreciated.  Smiley

Offline dbotha

Senior Newbie

« Reply #1 - Posted 2010-12-02 17:15:53 »

Are any errors networking related? I would start by fixing the errors in the graphics portion of code as hopefully you have a stack trace to work from. With regards to your firewall, if either client is behind a NAT router there is a good chance it is performing packet filtering (separate to your OS firewall). In this case you may want to ensure port forwarding has been set up appropriately to avoid some connectivity headaches. Also what transport are you using -- UDP or TCP? If you're using UDP then testing on LAN or locally on a single machine typically works as expected as often you'll never experience packet loss and reordering. It's difficult to provide any further suggestions without something more to work from Smiley
Offline SimonH
« Reply #2 - Posted 2010-12-02 17:47:15 »

I'd advise a test setup which ONLY does networking - no graphics or anything else. This should be easy to debug. When you've got this working reliably between multiple machines, plug the working code back into your game.

People make games and games make people
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline doby162

Senior Newbie

« Reply #3 - Posted 2010-12-02 17:56:04 »

None of the errors are network related and  the errors generated by the graphics section don't normally appear. also they originate in the Graphics library, not in my code, which leads me to believe that they aren't really to do with graphics, but are rather a by-product of the Main thread crashing.

my command prompt won't let me copy past but the errors start out with things such as "java.awt.event.InvocationEvent.dispatch< Unknown source>" and "javax.swing.RepaintManager$Paintmanager,paint< Unknown suorce>" and "exception in thread "AWR_EcentQueue_0" java.lang.nullPointerException"

It is worth noting that the most recent time I ran the game, it was perfectly playable for all of 5 seconds before it crashed. A record so far.  Undecided

As for the portion about the router, I have no idea. I probably have the default setting on everything local network related, but the game doesn't work on local networks either so idk...  Shocked

Im sorry I don't have many leads for figuring out the problem, but if I did I might have done a better job myself.   Wink

I guess I will try to explain the communication protocol I wrote... basically their is one Main thread for the host, which runs just about the same as in single player, and one thread per client which collects keystrokes from clients. The Main thread than prepares an array list of custom data holding objects, sends them over the network with a few Strings as well for other info, and the client uses the data to render an image on the screen. The graphics are really simple so it just uses a for loop and goes through the data points, painting one after another. I don't think I'm overloading the network, because according to the task manager the game never exceeds 0.50% of the network capacity. also at the beginning of the game their are only 2-3 data points, even though it can get to hundreds later on.

thanks!  Grin

P.S while I was writing this another post came through, which I will now respond to. I alredy made somthing similer at the begining that tested weather the connection worked, but I guess I've chanegd alot since than, so it might be a good idea to redo that. It will take a bit of time though, so I will post the results when I'm done.
Offline dbotha

Senior Newbie

« Reply #4 - Posted 2010-12-02 18:31:24 »

It's still pretty difficult to make any guesses to your problem but I have a suggestion based on my interpretation of your last post. Firstly are you using UDP or TCP? It sounds like you are continuously sending the 'data points' (an absolute state of the snake(s) if you will) every update tick or move. If you are using TCP this is a very very bad idea, if you are using UDP it's probably fine for what you are doing. If you're using TCP however I would recommend you only send state changes to save bandwidth i.e. send a command indicating the next move direction of a snake.

In situations where the host is behind a router (and the other client is external to this router) it's very likely your game will fail to establish connectivity if you have not set up port forwarding or similar. Also it's been a while since I've used Windows, however if I recall you can right click in the command prompt and choose "Mark" to highlight text for copy and paste.
Offline doby162

Senior Newbie

« Reply #5 - Posted 2010-12-02 18:46:22 »

Thank you very much, this seems promising and I will be sure to persue it. In the mean time though, everything I know about routers I learned in a basic computer science 101 class, which I took a couple of years ago as a high school guest student, so I'm not really sure how they work. After lunch I will try and find out things like weather I'm using UDP or TCP, but as of now I don't even know what those stand for. It shouldent take to long to study up on it though, I've still got my textbook and google is on my side.  Grin
Offline doby162

Senior Newbie

« Reply #6 - Posted 2010-12-02 21:11:17 »

I'm using TCP, which I guess means a lot of overhead form error catching. I have yet to look into configuring my ports, but in the mean time how would I go about switching to UDP? Also information on port configuration would be appreciated.
Offline zoto

Senior Devvie

Medals: 4

« Reply #7 - Posted 2010-12-02 22:04:43 »

It would be a lot easier to configure your router rather than rewriting your networking code to use UDP. Configuring your router varies depending what your using, and their site would probably detail exactly how to do it. The usual way on windows is to just type the IP address of your default gateway into the address bar of your web browser and finding the port forwarding options. To find the IP info on windows you can use ipconfig in the cmd prompt.
Offline doby162

Senior Newbie

« Reply #8 - Posted 2010-12-02 22:20:29 »

But what about other people who play the game? Will I have to include directions for changing router settings? If thats the case it might be easyer to change the code in the long run.
Offline dbotha

Senior Newbie

« Reply #9 - Posted 2010-12-02 23:10:06 »

Simply using UDP is not going to solve the problem, a clients router is just as likely to filter these incoming packets as it is TCP. Using UDP does however give you more reliability when it comes to NAT punch through, but I would not worry about this for now. As you appear to be starting out with networking I'd recommend you concentrate on getting the game playing well over the network first. Ignore the firewall aspects i.e. take the easy way out and get the host to port forward or similar, at least for now.
Pages: [1]
  ignore  |  Print  
You cannot reply to this message, because it is very, very old.

orrenravid (188 views)
2016-07-16 03:57:23

theagentd (259 views)
2016-07-11 14:28:54

Hydroque (341 views)
2016-07-06 05:56:57

Hydroque (492 views)
2016-07-03 08:52:54

GrandCastle (375 views)
2016-07-01 09:13:47

GrandCastle (366 views)
2016-07-01 09:09:45

CopyableCougar4 (421 views)
2016-06-25 16:56:52

Hydroque (401 views)
2016-06-22 02:17:53

SwampChicken (365 views)
2016-06-20 13:22:57

SwampChicken (298 views)
2016-06-20 13:22:49
Making a Dynamic Plugin System
by Hydroque
2016-06-25 00:13:25

Java Data structures
by BinaryMonkL
2016-06-13 21:22:09

Java Data structures
by BinaryMonkL
2016-06-13 21:20:42

FPS Camera Tutorial
by Hydroque
2016-05-22 05:40:58

Website offering 3D Models specifically for games for free
by vusman
2016-05-18 17:23:09

Website offering 3D Models specifically for games for free
by vusman
2016-05-09 08:50:56

Website offering 3D Models specifically for games for free
by vusman
2016-05-06 11:10:21

Website offering 3D Models specifically for games for free
by vusman
2016-04-29 12:56:17 is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!