我还应该使用 TCPClient 来编写服务器还是有更好的东西出现?
几年前,当我为一个简单的乒乓球游戏编写服务器时,我使用了 TCPClient 并引用了一些 .NET Framework 101 代码示例页,其中包括使用 .NET Framework 1.1 或 2.0 编写的服务器和客户端程序的示例。
我需要编写另一个服务器,我想知道现在是否有更好的东西可以使用。我记得代码相当低级,有很多 try-catch 和样板代码。
.NET Framework 2.0、3.0、3.5 或 4.0 在实现简单的客户端-服务器程序方面是否有任何进步?任何简单的用户创建的包装器怎么样?
顺便说一句,我不一定反对使用 TCPClient 类。我只是想知道是否还有其他东西可以进一步抽象类和/或促进服务器程序的创建。
Years ago when writing a server for a simple pong game I was making I used a TCPClient and referenced some .NET Framework 101 code sample page that included an example of a server and client program written using either the .NET Framework 1.1 or 2.0.
I need to write another server and I was wondering if there is anything better to use now. I remember the code being pretty low-level with a lot of try-catches and boiler-plate code.
Has the .NET Framework 2.0, 3.0, 3.5, or 4.0 had any advancements in the implementation of a simple client-server program? What about any simple user-created wrappers?
By the way, I am not necessarily against using the TCPClient class. I just am wondering if anything else has come along to further abstract the class and/or facilitate in the creation of a server program.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
WCF是一个不错的选择。它为您提供了很大的灵活性和力量。以下是简单的入门指南:MSDN 文档 - WCF 入门。这篇来自 Switch on the Code 的博客文章更加简单。
另一种选择是使用 C# 绑定到开源项目 0MQ。它抽象化了套接字的复杂性,而无需太多开销,并为您提供了强大的功能。来自 0MQ 部分的 100 个单词:
ØMQ(ZeroMQ、0MQ、zmq)看起来像一个嵌入式网络库,但其行为却像一个并发框架。它为您提供了跨进程内、进程间、TCP 和多播等各种传输方式传输完整消息的套接字。您可以使用扇出、发布-订阅、任务分配和请求-答复等模式连接 N 到 N 的套接字。它的速度足够快,可以成为集群产品的结构。其异步 I/O 模型为您提供可扩展的多核应用程序,这些应用程序构建为异步消息处理任务。它具有多种语言 API,并且可以在大多数操作系统上运行。 ØMQ来自iMatix,是LGPL开源
WCF is a great choice. It gives you a lot of flexibility and power. Here's a simple guide for getting started: MSDN Documentation - Getting Started with WCF. This blog post from Switch on the Code is even more straightforward.
Another option is the using C# bindings to the open source project 0MQ. It abstracts away the complexity of sockets without too much overhead and gives you a lot of power. From the section 0MQ in 100 words:
ØMQ (ZeroMQ, 0MQ, zmq) looks like an embeddable networking library but acts like a concurrency framework. It gives you sockets that carry whole messages across various transports like in-process, inter-process, TCP, and multicast. You can connect sockets N-to-N with patterns like fanout, pub-sub, task distribution, and request-reply. It's fast enough to be the fabric for clustered products. Its asynchronous I/O model gives you scalable multicore applications, built as asynchronous message-processing tasks. It has a score of language APIs and runs on most operating systems. ØMQ is from iMatix and is LGPL open source