.NET网络库

发布于 2024-09-03 02:20:17 字数 260 浏览 4 评论 0原文

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

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

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(7

若水微香 2024-09-10 02:20:17

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

此处尚未提及的库是 networkComms.net。它具有大量复杂的功能(例如序列化、压缩和加密),但考虑到您具体提到的连接数量,它能够以 1Gbps+ 的传输速率处理 1000 多个连接。有一篇简单的文章介绍如何创建快速客户端服务器应用程序< /a> 但简而言之,您可以按如下方式发送和接收。

发送:

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

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

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.

半透明的墙 2024-09-10 02:20:17

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

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/

往昔成烟 2024-09-10 02:20:17

您似乎找错地方了。您似乎没有查看 .NET Framework 本身。

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

你需要什么而这些却没有提供?

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?

心如荒岛 2024-09-10 02:20:17

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

我编写了一个库 Nito.Async.Sockets,它是 Nito.Async 的一部分。它消除了套接字编程中的多线程注意事项,并且还包括处理 的更高级别抽象消息框架keepalives

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.

独行侠 2024-09-10 02:20:17

利格伦怎么过时了?它仍然是 .NET 领域中唯一的主要参与者。用于游戏网络。

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

顾挽 2024-09-10 02:20:17

您是否尝试过 System.Net 中的内置 .Net 库?您根本不需要使用外部库。 这是简单线程 TCP 服务器的示例可能还想看看 UDP。如果你用谷歌搜索一下,就会有很多教程。

尝试查看 System.Net.Sockets MSDN 页面了解更多信息。

Have you tried the inbuilt .Net libraries found in System.Net? It is very unlikely that you need to use an external library at all. Here's an example of simple threaded TCP server and you may want to look at UDP as well. There are loads of tutorials if you just google around a bit.

Try looking at the System.Net.Sockets MSDN page for more information.

墨洒年华 2024-09-10 02:20:17

此时,我想将我的 放入此线程中。 NuGet 也可用

At this point I would like to throw my library into this thread. NuGet available as well.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文