.NET Network Library

20,356

Solution 1

Your link is indeed outdated; but if you read the page it will direct you to the newer version: http://code.google.com/p/lidgren-network-gen3/

Solution 2

Although there is nothing stopping you from writing all of the low level networking code yourself, using a library is definitely a great way to save loads of time and stress, time which you can then better spend improving your own application.

A library not already mentioned here is networkComms.net. It has a plethora of sophisticated features (such as serialisation, compression and encryption) but given you mention number of connections specifically it is capable of handling 1000+ connections with transfer rates of 1Gbps+. There is a simple article on how to create a quick client server application but in brief you could send and receive as follows.

To send:

//This is the simplest way to send with more advanced options also available
//Parameters are message type, IP address, port and the object to send
NetworkComms.SendObject("Message", "127.0.0.1", 10000, "Networking in one line!")

To receive:

//We need to define what happens when packets are received.
//To do this we add an incoming packet handler for 
//a 'Message' packet type. 
//
//This handler will automatically convert the incoming raw bytes into a string 
//(this is what the <string> bit does) and then write that string to the 
//local console window.
NetworkComms.AppendGlobalIncomingPacketHandler<string>("Message", (packetHeader, connection, incomingString) => { Console.WriteLine("\n  ... Incoming message from " + connection.ToString() + " saying '" + incomingString + "'."); });

//Start listening for incoming 'TCP' connections. The true 
//parameter means try to use the default port and if that 
//fails just choose a random port.
//See also UDPConnection.StartListening()
TCPConnection.StartListening(true);

Disclaimer: I'm one of the developers for this library.

Solution 3

How is lidgren outdated? It is still the only major player in the .NET space for gaming networking.

Solution 4

WCF is one possibility, though it may be a bit heavyweight for this scenario. .NET Sockets, OTOH, are often too low-level; they're not an easy "component" to just plug in (both networking and multithreading must be learned well before the Socket class can be used correctly).

I wrote a library, Nito.Async.Sockets, which is part of Nito.Async. It removes multithreading considerations from socket programming, and also includes a higher-level abstraction that handles message framing and keepalives.

Solution 5

You seem to be looking in the wrong place. You don't seem to have looked in the .NET Framework itself.

What about using WCF? What about using TcpListener?

What do you need that these do not provide?

Share:
20,356
Mark
Author by

Mark

Updated on October 04, 2020

Comments

  • Mark
    Mark over 3 years

    I've been looking for a decent network library for C#. It is going to be used with XNA 3.1, and .NET Framework 3.5. The multi-player style is going to be Server and Client. Currently I have been looking into Lidgren Library Network, but it seems outdated.

    Anyone got some good suggestions for a good network library. It should be able to handle easily 30+ client connections at a time.

  • Brett
    Brett over 11 years
    the lidgren library is solid, I've used it in a production setting with good success!
  • Andrew Barber
    Andrew Barber over 11 years
    Pretty much all of your posts are advertisements for what is obviously your website, and none of them disclose that fact.
  • MarcF
    MarcF over 11 years
    @AndrewBarber - For the record I am one of the developers for networkComms.net. I have never tried to hide that, I will amend my profile to clarify that now.
  • Andrew Barber
    Andrew Barber over 11 years
    Please be sure to read the FAQ on Self-Promotion carefully. Specifically, see the part where it says if many of your posts are promotional, you are probably here for the wrong reason. Also note that it is required that you post a disclaimer every time you link to your own site/product.
  • MarcF
    MarcF over 11 years
    @AndrewBarber - Understood, I was not aware of the of the disclaimer requirement.
  • Syaiful Nizam Yahya
    Syaiful Nizam Yahya over 10 years
    Do you have an echo client server example?
  • Syaiful Nizam Yahya
    Syaiful Nizam Yahya over 10 years
    I would not recommend Nito.Async as of this writing(v1). Quote from Nito.Async site "The current Nito.Async.Sockets API has been frozen. A new (v2) API will be developed that provides better separation between protocol components (e.g., type of message framing, keepalive system, etc., will all be orthogonal). The new API may be based on the Rx framework, but is more likely to be tied into the .NET 4.0 Task Parallel Library."
  • Syaiful Nizam Yahya
    Syaiful Nizam Yahya over 10 years
    While vanilla socket library can be sufficient for some people, people who doesnt like to manage resources efficiently should either look for network library or prepare to write a lot of resource management code(scaling, minimize garbage collector, multithread, load balancing, network error handling etc.).
  • Stephen Cleary
    Stephen Cleary over 10 years
    Nito.Async.Sockets is still usable; the v2 API has been planned for years but I just haven't had time to do it.
  • ANeves
    ANeves over 9 years
    Lidgren is now migrating to github: github.com/lidgren/lidgren-network-gen3
  • NeroS
    NeroS over 8 years
    Advertising a site for paid library, which hides the fact that it's a paid library behind "Download" link, which takes you to a "Please select package!" page with prices listed ... I'd prefer if it didn't try to hide the fact on quick look and instead had a "Purchase" link.