这段代码是如何工作的? (MUD服务器挡板的故事)
我在这个网站上找到了一些建立多线程聊天服务器的示例代码,其编写目的是扩展为简单的 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
啊,所讨论的 ArrayList 是
static
,这意味着它由Connection
类的所有实例共享。Ah, the ArrayList in question is
static
, which means that it's shared by ALL instances of theConnection
class.