General networking questions

So, the way I’ve been sending objects to a server is by creating the objects class in both the client project and the server project then just reading them in through a stream, is this the correct way to do so?

Another question I have is, If I were to create a simple multi-player game where a player would connect to a server and a new player object would be created, would I just create the server in a different project as usual, send the necessary data to the server, then have the server send back information that needs to be updated such as play positioning?

Last question is, for Peer-to-Peer where one player is the host, in terms of how the server and connections made, how exactly does it work, by which I mean when a new client joins where does it connect to?

Any help is appreciated! 8)

Peer-to-Peer is Client-Server where one of the ‘clients’ is a server in disguise.

You may want to look at the posts:

So, I was thinking it would go like this, the first player would start a new game, this would then create a server at the port the user enters, the game would then wait for a connection from a client which would then start the game, so in turn although there would be 2 players, one is the actually the server and the other is the client. Am I on the right track for this? Thanks!

Yes it sounds like you are on the right track.

Assuming you are using java sockets, the player acting as the server will create a ServerSocket on the desired port. The player acting as the client then connects using a Socket to the server’s IP and port.

If the player acting as a server is sitting behind a router however, they will more than likely have to enable port-forwarding for the particular port that your game is running on. Although this would be up to the player to sort out, as the method varies for different routers. I’m not sure if there is any way around this; if there is perhaps someone more experienced than me can fill you in.

EDIT: (I always edit my posts… :clue:) Just food for thought, if you are still learning the ropes when it comes to networking, perhaps you could try create a simple chat application or similar for starters? Much of the networking theory would be the same, well at least in terms of clients connecting to servers etc. That way you can focus on the networking side of things, instead of trying to build a game and learn networking at the same time. I don’t have any idea of your experience or anything, so sorry if it sounds like I’m trying to teach you to suck eggs!! :slight_smile:

nerb.

Any decent router should support NAT-PMP, which will open the ports invisibly. Google searches suggests there’s plenty of implementations out there for java. You could also use UPnP but it’s starting to wane in popularity for various good reasons.

Thanks guys, Yeah I created a small chat program I actually know a fair bit but was struggling in applying it to game development. I have as of now implemented what I was trying to do and it worked, I have been able to let a player type in a port and the player gets connected to the server at that port and have been able to send objects and handle them on the server. Thanks!