[C#] TCP or HTTP networking library similar to Lidgren? For sending game map data.

Started by
4 comments, last by gooby 5 years, 10 months ago

Hi,

 

I am looking for a TCP or HTTP networking library similar to Lidgren (UDP).

 

This is primarily for sending game map data and potentially other large messages from Server to Client.

 

I do want to keep Lidgren for my chat messages, player position, small fast updates etc. I especially love the flow of data and the library usage in general, so any libraries of a similar style would be excellent. Preferably something open source, free and reliable.

I also must be able to swap between localhost and an ip address with ease, like Lidgren, as I run a server for singleplayer/mp/lan.

 

My game maps are similar to minecraft, but it is 2d and only one Z-level, so i'm sending a jagged array of Tile object data (currently only enum TileID.Grass) down the pipe to the Client. Problem is if i'm sending a large map 1024 x 1024 tiles down the to client that's quite a lot of data, and Lidgren is relatively slow to build the writes (before the message is even sent!). It is fine when i'm using smaller maps < 512 x 512 ( xTiles * yTiles ).


I know about chunking and will look into implementing this later, whilst taking into account the user's position in the world to only send nearby chunks.

 

An example of my code that can be slow:


 private void WriteWorld(NetOutgoingMessage outgoing)
        {
            try
            {
                var world = WorldManager.Instance.CurrentWorld;

                outgoing.Write(world.XTiles);
                outgoing.Write(world.YTiles);

                for (int x = 0; x < world.XTiles; x++)
                {
                    for (int y = 0; y < world.YTiles; y++)
                    {
                        // Write Tile obj data
                        outgoing.Write((int)world.Tiles[x][y]); // <-------- Slow here when xTiles and yTiles are each > 512 !
                    }
                }

            }
            catch (Exception ex)
            {
                // log send error
            }
        }

 

I'd love to hear from you guys, especially if any of you have come across a similar challenge.

Advertisement

There aren't that many open source, robust, game-specific networking libraries for C#.

Why do you need to switch from Lidgren? What does "uses Monogame" mean? Networking is almost entirely separate from the game rendering library.

enum Bool { True, False, FileNotFound };
On 6/19/2018 at 7:23 PM, hplus0603 said:

There aren't that many open source, robust, game-specific networking libraries for C#.

Why do you need to switch from Lidgren? What does "uses Monogame" mean? Networking is almost entirely separate from the game rendering library.

Hi, I took out "uses monogame" as it probably confusing.

I am trying to see if anyone else had a very similar scenario as myself.

I was finding Lidgren writes very slow in a loop of alot of data and wondered if TCP or some other method would be a better alternative for sending map data from Server to Client.

Do you have anything at all in mind that could help?

 

EDIT:

I am also concerned about the following:

https://groups.google.com/d/msg/lidgren-network-gen3/6AQ94QnVaSk/xqQhMpq6YdIJ

"if the application keeps sending data onto a congested line it'll choke sooner or later - and Lidgren doesn't have any good solution for backing down gracefully (like TCP does). Lidgrens strong points are small, unreliable or sequenced messages with small reliable messages mixed in; if you know you'll be sending large amounts of reliable data you might either want to look into something else (like TCP) or manually do congestion control (send a chunk, wait for confirmation, send another...)"

I'm assuming this is initial map download data?

The best protocol for bulk data transfer is HTTP. If the server is publicly addressable, you can spin up a HTTP server on some known port, and tell the client which URL to use to download the map. If the server is not publicly addressable, you can perhaps set up a separate central map server, or use some Dropbox or Google Drive or OneDrive connection to share the map data.

enum Bool { True, False, FileNotFound };
1 hour ago, hplus0603 said:

I'm assuming this is initial map download data?

The best protocol for bulk data transfer is HTTP. If the server is publicly addressable, you can spin up a HTTP server on some known port, and tell the client which URL to use to download the map. If the server is not publicly addressable, you can perhaps set up a separate central map server, or use some Dropbox or Google Drive or OneDrive connection to share the map data.

You are correct, it is initial map download data.

I will look into HTTP. Thank you.

This topic is closed to new replies.

Advertisement