Monogame networking over internet?

I found an XNA tutorial which uses the networking features.
Are those features supported in monogame? I would guess so, since it’s basically a better XNA, but I would like confirmation.

Also, according to this link, you can only do local connections? It says it requires a XBox Live Membership for the online stuff.
What if you want to use your own server? How would that work?

2 Likes

MonoGame includes the Lidgren Network framework.
cf Preferred Networking Framework

How to: https://www.youtube.com/playlist?list=PLD2t5VOqzPm96kjLo1oYCG1dE38IqQzxI

You need an xbox live membership to play online with XNA, same as for online play on XBOX
But nothing prevents you from using another library (which will probably won’t integrate a lobby, avatars etc).

1 Like

Thank you for the video series, I appreciate it. Since I never did anything related to game networking, I wasn’t sure what to look for.
I actually stumbled over Lidgren shortly after I posted this question. I’m currently reading the introduction.

A related question: Is it easier to host on external server or on my own machine?

The networking support using Lidgren in MonoGame has not been maintained for a long time now.

FIrst of all, game networking is hard, even more so over the internet. Here is an article on Gamasutra from the developers of Square Heroes, a MonoGame-based title with fast-paced networking. There’s a bunch of useful links at the bottom of the article for further information.

1 Like

With “not maintained”, you mean there’s better ways? Is it usable?

My game is a turn-based (slow-paced) card game where basically the only action is to move cards, so I don’t need fast updating like other games. I hope that will make it easier to construct a working client/server communication.

I mean, I could probably do it with something like Hamachi if it’s too hard over the internet, but what is the problem that makes it so hard to do specifically over the internet?

By internet, do you mean a server?

In that case it would mean finding a host server and probably paying for it, ensuring it is up 99%+ time etc.

I think Hamachi is just TCP/IP right?

For this, Lidgren or FalconUDP (what Square Heroes uses) is probably unnecessary, although it would work. You’d need to write your own matchmaking server and pay to host it (no, it’s not a good idea to host it on your home PC!). Probably the best bet would be Photon, particularly since your game is turn-based (async networking only). I haven’t tried it but apparently it has built in matchmaking so you don’t need to worry about that side of it, and until your game gets more than 20 concurrent users, it’s free: https://www.photonengine.com/en-US/Realtime

Just looked a bit at the documentation and am I understanding correctly that I don’t need to write server-side logic for this? Since it already implements message sending and rooms.

That’s my understanding. You might want to look into it further, but yes, I think you can just get people connected without any custom server code.

Monogame online is impossible, when you don’t know about something, please keep your mouth shut, it will save everyoen time.

3 years later

.
.

Monogame online is impossible…

humm concerning.

Online Monogame is NOT impossible. You could use any C# networking library to implement networking that is completely separate from Monogame. Since there are C# networking options available, this is completely able to be done.

1 Like

@James_Dunlap
I’m having a play around at the moment with Networking. Given commercially (websites) I’m familiar with Microsoft’s SignalR, and now MonoGame builds with .NET Core, I’m going to give this a try. SignalR uses Websockets, and has clients for lots of platforms - most notable being javascript. But C# code can call and receive messages over the internet with SignalR. In theory you could start playing with it at home with your own router and port-forwarding so you are effectively self-hosting. But if you’re happy to pay a minimal fee each month you could have Azure hosting, and then you’ve no fear about hackers or anything. That’s the road I’m currently travelling. SignalR will work in a local area network (mine’s running as a separate project, as a console app listening on port 5001), and I’m getting response times of about 7ms from my MonoGame to the server app running on my machine. So Lan Party style gaming should be quite easy. Its harder over the internet with really slow ping times, and depending on the game type, you might want a lock-step solution, or you might need to get creative with code that predicts movements because the server will be a little delayed keeping you up to date. That’s about physical distances and the number of hops from server-to-server getting to and from the destination you’re trying to communicate with.
I found this to be a good read: https://www.gamasutra.com/blogs/MarkMennell/20140929/226628/Making_FastPaced_Multiplayer_Networked_Games_is_Hard.php and still very relevant today. Not a lot of point linking to SignalR, there’s millions of documentation out there for it.
I hope anyone reading this finds it useful. SignalR may not be the fastest solution, but it’s pretty easy to define a ‘hub’ and get going!

Hi everyone

Currently I am developing a face paced multiplayer game. It took me a lot of reading and time. Its hard.

To simply share some experience with you lads:

  • If you plan to develop a slow paced game (like a turn based game, like chess) then always use TCP/IP. It saves you a lot of time.
  • If you plan to develop a game where everything goes fast over the internet (like Quake Arena, Racing Games, Shooters, whatever) always use UDP because of speed.

Further, I have used this very old library, called lidgren. It works very well. I have not seen any bugs. I recommend it. There are some examples on the internet, where you have a minimal gameserver and gameclient running. To save data I used the concept of serializing and deserialising of data which should go over the internet.

Also, what I felt very very tricky was conceptional. I used the authoritative model where the server is the only one who actually runes the game and sends the positions of each gameobject to his clients. The clients are dumb. They do not posses any logic. They just position the objects according to the received positions of the server. The server also sends them the ID-Number, when they have to create or destroy any gameobject. Now, if you have a face paced game (which in your case you don’t) you need to interpolate. Why? Because if the client only received a packets every 100 ms the stuff laggs terrible. Therefore, you need to interpolate stuff. Linerar Interpolation is easy but Non-Linerar-Interpolation with Curves is really difficult. There is tons of math waiting for you. I found some code on the internet, which solved this problem for me. What did I do? My server sends every 100ms another Network paket, where all the states are included (a state includes a position and rotation of an existing game object. So the server sends that and his clients will receive that. The client (which are 100% dumb with no game logic, just object placing on screen) received the latest position and together with his past 2 positions (which he received even earlier) he calculates all points in between (called Interpolation). So my Interpolation class can calculate out of 3 points many points, whether those points a linear or non-linerar. Thanks to interpolation the game feels interactive, responsive, lag-free.

In case someone is interested in this source code, feel free to write me here.

So in short: Multiplayer is a pain in the ass. Start with something simple. If its turn based with no nonlinear interpolation, I guess its so much easier.

Some Hints for you (they really helped me to understand concepts)

All the stuff I described up here I have tested on Windows, macOS and Linux. It works (including multiplayer). About XBox, and so on, I have absolutely no clue.

Kind Regards
Andru.

1 Like

Professionals call it ‘prototypes’. The first rule of prototypes (in a really high-end company) is to throw them away. They’re there to learn from, and make the mistakes, where we’d normally say “if I had a chance to do it again, knowing what I now know, I’d…” - then you start again. As far as professionals go, I can tell you, I’ve seen plenty of prototype code go live.

There’s even a saying for that, as it is actually very common… “There’s nothing more permanent, than a temporary fix!”. Given the nature of temporary fixes - usually some very brittle code the client comes to depend on that’s not backed by any tests, etc - they’re reluctant to risk you fixing the fix!

  • another day in developer heaven.

I’m thinking of looking at UDP with Lidgren after I’ve finished playing with SignalR - for all the reasons mentioned in the links you provided. SignalR seems ok at the moment, with just me messing around with my server, but I’m sure it could go faster with UDP! I’m thinking a series of 4 (not 5, shock!) rows of history per update would be enough for UDP. Given I’ve been around since the Commodore 64 (showing my age) I know a thing or two about packing data into bytes. A throw-away for C# guys woudl be - get to love enumerations you can use as bit-fields. You can convert a byte to enumeration by casting. Very handy, and doesn’t hurt performance in any way. Here’s a link explaining: C# Language - Enum as flags | c# Tutorial secondly, your can overlay different types into the same memory addresses inside a struct. [StructLayout(LayoutKind.Explicit)] StructLayoutAttribute Class (System.Runtime.InteropServices) | Microsoft Docs - so you can have 4 bytes overlaying an int’s memory address, meaning you can pull out the bytes or convert from bytes back to an int very easily. Now, that’s a trick not many “professional” C# developers know about. :slight_smile:

Hi together

I have received some feedback. Sadly, I did not check it for a long time. Based on those questions I have set up a little HowTo. Sadly, I did not really find the time to explain all those stuff I did. Mostly I referred to other websites I have used.

One good thing: I have found some old source-code which I wrote in Zermatt. I developed a console chat in order to test protobuf and lidgren.core (or core2)

Feel free to download the source code of lidgren-chat. On this messy website you will find it.
https://andru.ch/bin/view/Development/Lidgren-Chat/

Kinds Regards
Andru

There’s nothing more permanent, than a temporary fix!

I agree 100%. Same experience.