.NET网络库

时间:2010-05-22 12:11:06

标签: c# .net-3.5 networking xna

我一直在寻找一个适合C#的网络库。 它将与XNA 3.1和.NET Framework 3.5一起使用。 多人游戏风格将是服务器和客户端。 目前我一直在研究Lidgren Library Network,但它似乎过时了。

对于一个好的网络库,任何人都有一些好的建议。它应该能够一次轻松处理30多个客户端连接。

7 个答案:

答案 0 :(得分:10)

虽然没有什么能阻止您自己编写所有低级网络代码,但使用库绝对是节省大量时间和压力的好方法,您可以更好地花时间改进自己的应用程序。

此处尚未提及的库是networkComms.net。它具有许多复杂的功能(例如序列化,压缩和加密),但是如果你提到连接数量,它就能够处理1000多个连接,传输速率为1Gbps +。 how to create a quick client server application上有一篇简单的文章,但您可以按照以下方式发送和接收。

发送:

//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!")

收到:

//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);

免责声明:我是该图书馆的开发人员之一。

答案 1 :(得分:3)

您的链接确实已过时;但如果您阅读该页面,它将引导您使用较新版本:http://code.google.com/p/lidgren-network-gen3/

答案 2 :(得分:2)

你好像在寻找错误的地方。您似乎没有查看.NET Framework本身。

使用WCF怎么样?如何使用TcpListener

这些不提供什么需要?

答案 3 :(得分:2)

WCF是一种可能性,尽管对于这种情况可能有点重量级。 .NET套接字,OTOH,通常太低级;它们不是一个容易插入的简单“组件”(在正确使用Socket类之前,必须很好地学习网络和多线程)。

我写了一个库,Nito.Async.Sockets,它是Nito.Async的一部分。它从套接字编程中删除了多线程注意事项,还包括处理message framingkeepalives的更高级抽象。

答案 4 :(得分:2)

lidgren如何过时?它仍然是.NET space for gaming networking中唯一的主要参与者。

答案 5 :(得分:1)

您是否尝试过System.Net中的内置.Net库?根本不需要使用外部库。 Here's简单线程TCP服务器的示例,您也可以查看UDP。如果你只是稍微谷歌,有很多教程。

请尝试查看System.Net.Sockets MSDN page以获取更多信息。

答案 6 :(得分:-1)

这时,我想将我的library放入该线程中。 NuGet available as well