在 C# 中创建严格限制的服务器发现应用程序
我写信给你是因为我需要解决一个新问题,而我现在已经把头撞在墙上太久了。
基本上,我需要创建一个可以处理以下任务的应用程序:
用户启动一个应用程序,该应用程序向子网发送广播,并接收所有服务器及其 IP(以及一些附加信息)的响应。然后用户可以选择他想要连接到的服务器。
使其工作非常简单,只需识别子网并使用 UDP 进行广播,然后让不同的服务器应用程序接收它并发回响应。问题在于这些限制,我需要考虑这些限制:
- 网络中的服务器计算机上很可能也有客户端,这意味着我们可以假设该应用程序存在于所有计算机上。每台机器都需要运行侦听器,并且每台机器都可以启动 GUI 来选择服务器。
- 我只被允许向防火墙添加一个例外 - 一个处理发送广播、接收广播、发送答案和接收答案的例外。
- 我还应该只在服务器计算机上添加一个 Windows 服务
- ,侦听器应该作为 Windows 服务运行,这样用户就不会注意到它。用户也不会注意到响应已发送回客户端。
- 在客户端计算机上,用户可以启动一个应用程序,该应用程序将通知该应用程序发出广播,并获得所有服务器响应,因此用户可以选择一个进行连接。
- 除了用户启动以选择服务器的应用程序之外,不应与用户进行任何交互。甚至没有一个弹出窗口,请求用户允许流量通过防火墙 - 它应该是自动的
- 它需要在 Win XP、Win Vista 和 Win 7 上及其之间工作。
我不知道我是否对它施加了太多限制我自己,但我真的希望我能满足这些要求来申请。
我有一些想法 - 我只需要弄清楚如何做到这一点:
- 我应该将所有内容都放入一个应用程序中,然后将其添加到防火墙例外列表中,这样它将处理服务器和客户端计算机上的流量?
- 我是否应该向防火墙添加自定义例外,允许特定端口上的 UDP 流量,然后让所有流量通过该端口?
- 是否有第三种更好的选择来管理这个问题?
- 可以让服务同时在客户端和服务器计算机上运行。但是它可以为我处理所有事情吗 - 就像它处理广播发送/接收和应答发送/接收一样?有没有办法从服务中提取有关网络上服务器的信息?
我知道有很多,但我真的希望你能帮助我。
如果我不够清楚,或者您需要进一步的解释,请告诉我。
我正在使用 C# .Net 进行编码,并且我可以利用 .Net 框架中我想要的所有内容。一旦我实现了此功能,
一切顺利
/Sagi
I am writing you because of a new problem I need to solve, and I have now been banging my head against a wall for too long now.
Basically, I need to create an application that can take care of the following:
A user starts an app, which sends a broadcast to the subnet, and recieves a response of all servers there with their IP (and some additional info). The user can then select what server he wants to connect to.
Making it work is simple enough, with identifying the subnet, and broadcasting with UDP, and then having a different server application recieving it and sending back a response . The problem lies with these restrictions, that I need to take into consideration:
- There will most likely also be clients on the server machines in the network, meaning that we can assume that the application is present on all machines. Every machine needs to have the listener running, and every machine can launch the GUI for selecting a server.
- I am only allowed to add one exception to the firewall - an exception that handles both sending out the broadcasts, recieving broadcasts, sending answers and recieving answers.
- I should also only be adding one Windows Service
- on a server machine, the listener should run as a windows service, so the user won't notice it. Nor will the user notice, that the response is sent back to the client.
- On the client machine, the user can start an application, which will notify the application to emmit the broadcast, and will get all the server responses, so the user can choose one to connect to.
- Besides from the application that the user launches in order to select a server, there should be no interaction with the user whatsoever. Not even a popup, requesting the user to allow traffic trough the firewall - it should all be automatically
- It needs to work on and in between Win XP, Win Vista and Win 7.
I don't know if I am putting too many constrains on myself, but I really hope that I can make the application with these requirements.
I have a few ideas - I just need to figure out how to do it:
- Should i make everything into one application, that I add to the firewall exception list, so it will take care of the traffic on both the server and the client machines?
- Should I add a custom exception to the firewall, allowing UDP traffic on a specific port, and then have all traffic flow trough that?
- Is there a third and better option for managing that?
- It is OK to have the service running on both client and server machines. But can it take care of everything for me - like it handling both the broadcast send/recieve and answer send/recieve? And is there any way to extract the information about servers on the network from a service?
I know it is a lot, but I really hope that you will be able to help me out.
let me know if I wasn't clear enough, or if you need further explanations.
I am coding in C# .Net, and I can utilize all I want from the .Net framework. As soon as I have this functionality implemented
All the best
/Sagi
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您指定一台机器作为主服务器,这种对等网络问题就会变得简单到微不足道。它应该有一个所有子服务器都可以连接的众所周知的名称,以便它们可以发布(和撤回)其可用性。然后,客户端可以向同一服务器发送查询请求,并获得已知服务器的列表作为返回。
这也可以解决您的防火墙问题,主服务器可能正在侦听端口 80。
查看 System.Net.PeerToPeer 命名空间以获取框架支持的 p2p 解决方案。
The kind of peer-to-peer networking problems become simple to the point of being trivial if you designate one machine as the master server. It should have a well-known name that all sub-servers can connect to so they can publish (and withdraw) their availability. A client can then send a query request to the same server and get a list of known servers in return.
This can also solve your firewall problem, the master server could be listening on port 80.
Look into the System.Net.PeerToPeer namespace for a p2p solution supported by the framework.
也许 UPnP 服务器和客户端可以解决您的问题?
Maybe a UPnP server and client may be a solution to your problem?