我想编写一个具有娱乐目的的应用程序。这应该是一个桌面应用程序,它检测自己在同一 LAN 上的其他计算机上运行并与它们通信。我所说的沟通是指我应该能够将任何东西传递给另一个人。
请注意,虽然我不要求代码(当然,这会超出我的目的),但我认为一些小片段不会有什么坏处。无论如何,我真正想要的是“推荐的过程”,我的意思是微软对此环境的推荐以及文档:)
I want to code an app with recreational purposes. This should be a Desktop app that detects itself running on other computers on the same LAN and communicates with them. By communication I mean that I should be able to pass anything from on to another.
Please note that although I'm not asking for code (that would beat my purpose, of course) I think some small snippets wouldn't hurt. In any case what I really want is the "recommended procedure", I mean what Microsoft recommends for this environment, and documentation :)
发布评论
评论(3)
如果这是您的第一个网络应用程序,您应该从套接字开始,这样您就可以理解并理解从头开始构建这样的应用程序所涉及的问题。实际上,您尝试构建的是一个点对点应用程序。您需要在这里考虑和研究很多事情,例如:
。
最终(一旦您理解了基本概念),您将希望将所有这些都推迟到框架中,而不是从头开始开发所有内容 我认为 WCF 对等 会满足您的需求。
If this is your first ever network application, you should start with sockets so you can understand and appreciate the issues involved in building an app like this from scratch. Effectively, what you are trying to build is a peer-to-peer application. There are many things you'll want to think about and research here, like:
attacks, etc.
Eventually (once you've understood the underlying concepts), you will want to defer all of this to a framework rather than developing everything from scratch. I think WCF peer-to-peer will fit your needs.
正如 Taz 所说,套接字编程是最好的选择,但您可以使用其他解决方案,例如 WCF(通常不推荐)。
关于在
LAN
上查找其他实例,我可以说您需要一些扫描算法。大多数蠕虫病毒都有这样的传播算法。您应该考虑许多网络问题,例如目标 LAN 上的开放端口和防火墙限制。另一点可以使用超过 5000 的 TCP 端口(最多 65535,但不要使用著名端口),因为 5000 以下的端口可能会被操作系统使用。
还需要您自己的 TCP/IP 协议用于对等点之间的消息传递/命令和数据传输。
最后,在此类项目中获得网络/安全顾问的帮助是个好主意,因为您遇到的大多数问题与编程无关,而是与网络有关。
As Taz said socket programming is the best choice but you can use other solutions like
WCF
(not recommended normally).About finding other instances on the
LAN
I could say you need some scanning algorithm. Mostworms
have such an algorithm for spreading. You should consider many networking issues like open ports on targetLAN
and firewall restrictions.Another point could using a
TCP
port over 5000 (up to 65535, but don't use famous ports) since ports under 5000 are subject to be used by operating system.Also to need your own protocol over TCP/IP for messaging/commanding and data transfer between peers.
At the end it's a good idea to have a hand from a networking/security consultant in this kind of projects since most problems you encounter are not about programming but networking.
套接字编程?让它们侦听特定端口,每当应用程序启动时,它都应该连接到该套接字,并且它们都已连接。我不确定应用程序应如何搜索在 LAN 上运行的其他应用程序实例。
Socket programming? Make them listen on a specific port and whenever application starts it should connect to that socket and the they are both connected. I am not sure how should application search for other application instances running on LAN.