c# - .NET 网络库

标签 c# .net-3.5 networking xna

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

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

最佳答案

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

此处未提及的库是 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);

免责声明:我是这个库的开发者之一。

关于c# - .NET 网络库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2888012/

相关文章:

c# - MVVM ViewModel 很多属性

c# - 将 Linq To Sql Binary 字段设置为 null

vb.net - 在托管代码中启动另一个 EXE

.net - 调用 .NET 3.5 Web 服务的 Java 客户端程序

c# - 访问汽车属性中的支持字段

networking - 网络图中的边缘方向

c - TCP 非阻塞连接失败,getsockopt OptValue 113 请建议

c# - 将自定义字体添加到 Windows Phone 8 应用程序

c# - IBM.Data.DB2.Core 在 azure 函数应用程序中引发异常

python - 序列化 ctype 联合