Mar*_*ark 3 c# networking xna .net-3.5
我一直在寻找一个适合C#的网络库.它将与XNA 3.1和.NET Framework 3.5一起使用.多人游戏风格将是服务器和客户端.目前我一直在研究Lidgren图书馆网络,但它似乎已经过时了.
任何人都有一个好的网络库建议.它应该能够一次轻松处理30多个客户端连接.
Mar*_*rcF 10
虽然没有什么能阻止您自己编写所有低级网络代码,但使用库绝对是节省大量时间和压力的好方法,您可以更好地花时间改进自己的应用程序.
这里没有提到的库是networkComms.net.它具有许多复杂的功能(例如序列化,压缩和加密),但是如果你提到连接数量,它就能够处理1000多个连接,传输速率为1Gbps +.有一篇关于如何创建快速客户端服务器应用程序的简单文章,但简而言之,您可以按如下方式发送和接收.
发送:
//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!")
Run Code Online (Sandbox Code Playgroud)
受到:
//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);
Run Code Online (Sandbox Code Playgroud)
免责声明:我是这个图书馆的开发者之一.