我一直在寻找一个不错的C#网络库。
它将与XNA 3.1和.NET Framework 3.5一起使用。
多人游戏的模式将是服务器和客户端。
目前,我一直在研究Lidgren Library Network,但它似乎已经过时了。
有没有人对一个好的网络库有什么好的建议?它应该能够轻松处理30个以上的客户端连接。
有没有人对一个好的网络库有什么好的建议?它应该能够轻松处理30个以上的客户端连接。
//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);
你似乎在错误的地方寻找。你似乎没有查找.NET Framework本身。
那使用WCF呢?那使用 TcpListener
呢?
这些都不能满足你的需求吗?
WCF是一种可能的选择,尽管对于此情景来说可能有些笨重。.NET Sockets则通常过于低级;它们不是一个容易“插入”的组件(在使用Socket类之前必须学好网络和多线程)。
我编写了一个库,Nito.Async.Sockets,它是Nito.Async的一部分。它从套接字编程中去除了多线程考虑,并且还包括一个更高级别的抽象,可以处理消息分帧和保持连接。