这段代码是如何工作的? (MUD服务器挡板的故事)

发布于 2024-10-21 12:56:49 字数 520 浏览 5 评论 0原文

我在这个网站上找到了一些建立多线程聊天服务器的示例代码,其编写目的是扩展为简单的 MUD:http://bytes.com/topic/c-sharp/answers/275416-c-mud-telnet-server

该线程很旧,所以我不能在那里问任何问题,所以我想我应该向 stackoverflow 的好心人求助,帮助向我解释一些事情。

在开始编写 MUD 之前,我想了解上面的代码(我打算将其用作入门的基础)是如何工作的,这样如果我需要以不同的方式工作,我可以修改基本架构。但我不明白的是,它如何为每个 Connection 启动新线程,该 Connection 实例化自己的连接 ArrayList,它仅将自身添加到其中,但仍然与其他用户通信。

我假设这是对线程如何工作或类似的东西缺乏基本的了解,但无论我盯着该代码多久,我都无法弄清楚。

提前致谢, 哈吉德

I found some sample code establishing a multi-threaded chat server, written with the intent of being expanded into a simple MUD on this website: http://bytes.com/topic/c-sharp/answers/275416-c-mud-telnet-server

The thread is quite old, so I can't ask any questions there, so I figured I'd turn to the kind folks at stackoverflow to help explain something to me.

Before I get into writing a MUD, I'd like to understand how the above code (which I intend to use as a base to get started) works, so I can modify the basic architecture if I need things to work differently. What I don't understand though, is how it can be starting new threads with each Connection which instantiates its own ArrayList of connection, which it only adds itself to, but still communicate with other users.

I'm assuming it's some basic lack of understanding of how threads work or something of the sort, but no matter how long I stare at that code I can't figure it out.

Thanks in advance,
HJD

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

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

发布评论

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

评论(1

花开半夏魅人心 2024-10-28 12:56:49

啊,所讨论的 ArrayList 是static,这意味着它由 Connection 类的所有实例共享。

Ah, the ArrayList in question is static, which means that it's shared by ALL instances of the Connection class.

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