Lidgren Network

Hi all

MG: 3.5

I’ve recently been looking at the Lidgren Network library and all the examples I’ve seen has a “client / server” setup where the server is a separate “console” application. A little “game” I was messing around with last year is either one player or two players (using the same keyboard/monitor when in 2p mode) - I would like to turn this into a network game for 2 players so the 2nd player can use their own keyboard/monitor (and not be in the same room of course).

I know it must be possible but can the game it self also be the server for the other player - is this a wise way to do it rather than have a separate console application to run as a server for both players?

If so - Does anyone have any examples of this - I’m not that up on threading etc so wouldn’t know how the “game update()” method would work to update player one AND to also send out information to player 2, as well as also receiving the information (from a player 2 point of view).

Hope that’s not too confusing.


You can make your client application to also be a server application, that is have host start a server part on a separate thread and make it connect to itself (duno if you know this, but use as address for connecting to on host, that address is a loopback address, that is it always connects to itself).

Also since you mentioned you are bad with threading, read up:

@harry-cpp Thanks for the quick reply, Yes, I know about the “localhost” IP address and thanks for the link - currently reading up on “Task”:slight_smile: - not sure I fully explained what I’m trying to get at, so here goes. Lets take the game of PONG as an example a simple 1 or 2 player fast game.

1 player - we have AI controlling ball and other paddle
2 player - we have AI controlling just the ball

Now when the game is in ONE player mode - do I still use the server/client network to send/receive packets - even through it’s localhost, wouldn’t this slow the game down as it’s now using the network to transfer information to itself?

If the game is in 2 player mode, then one of the clients would need to be the “host” so the other client then connects to the host (player 1) and then player 1’s machine would send the network packets to BOTH players

What I think it should be is that a one player game is coded to NOT use the lidgren library and the client controls the ball / paddle #2 but in a 2 player game, it then uses the library.

What I’m basically asking - does anyone have a “pong” type game that is developed like this for me to look at and learn from?

The reason why it’s good to make single player mode use server/client is because you don’t get any code duplication. Yes you could make single player not require server, but than you’ll have to write a fully separate multiplayer system.

If you manage to make the game slow from singleplayer using the above method then you are doing something very very wrong.

@harry-cpp - Many thanks for the positive response, think I’ll have to try and make this pong game just to get the hang of it to see how to go about doing it. It does make sense to use the network calls for one player game from a writing point of view.