Network Error with my Multiplayer Pong (First Attempt)

Hello! This is my first attempt at creating an “online” game. I’ve created a chat client, which is actually quite easy compared to game networking. Anyways, I’m pulling some odd errors that I have no idea how to fix. Here’s a Github of the project I created:


I also have some images:
Server Error: As can be seen, the program itself works, but the networking throws an error while listening for the client

Client Error: Program doesn’t work at all, and I’m not sure why…

The “Server” is being run on my own desktop computer, and the “Client” is being run on my brother’s laptop. We are connected via a WiFi signal to the router, so I wasn’t sure which IP to connect to. We’ve been using my external, which has the port (7777) forwarded that we’re using. Thanks in advance for and and all help!

The ConnectedPlayer’s DataInputStream is set to null…

Come on, this is a simple NullPointerException, the famous NPE, the million dollar mistake…

Should always be easy to fix.

The better question should be:
Why is the ‘in’ DataInputStream in this line [icode]null[/icode], even though you create a new instance right above that line…

Need to look a little into the code. Try to debug it with eclipse or any other IDE.

I know about the NPE and everything, but there isn’t any obvious reason for it to appear. It runs perfectly fine when using localhost during Eclipse debug-runs, but as soon as I try to connect from anywhere that’s not localhost, or another computer, it throws the errors. I’m currently using Eclipse, and it doesn’t give any warning or pointers to anything. Usually, asking for help is my last resort, so I’m really stuck on this one part. I double checked the way that the inputstream you mentioned is made, I it looks/seems fine to me. You wouldn’t happen to have any ideas, would you?

At the risk of sounding like a broken record, you need to stop interfering with Java’s exception handling model. I’ve seen quite a few places in your code where you catch exceptions rather than let them propagate, but do nothing with them except sometimes write to System.out. The program just continues on as if nothing went wrong, resulting in NPEs later on. This makes debugging so much harder than it needs to be.

Learn to use the throws clause. Don’t write catch blocks unless you can do something appropriate with the exception. Remember - exceptions are like alarms. All catching them does is turns the alarm off. If you aren’t doing something to handle the exception, don’t catch it.