views:

159

answers:

2

Dear community.

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

+1  A: 

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.

Hans Passant
The problem is, that it needs to work on many different networks, and we cannot guaranteee taht they will set up a master server.I know it complicates things, but I need to work without it. Thanks for you quick reply.
Sagi1981
I will look into the System.Net.PeerToPeer to see if it can help me.If i didn't clarify it, the users have a seperate client server application in their network, where they now can manually input the IP/name of the server they wish to connect to. The applcation should broadcast, and identify machines where the servers are running on, and they should transmit thir adresses.How their netowrk is set up is something I do not know - and I cannot expect to have one 'staticly' named master server taking care of it.But it might be me totally misunderstanding you, and if so, then I apologize.
Sagi1981
The Peer to peer option seems like it could solve the problem. But I will need to have it enabled in windows components-> networking services.I cannot guarantee that the user will have this option enabled, and don't it open up for potential security breaches?Or am i wrong in assuming that you need that component in order for it to work (I tried with an example, which i found here: http://blogs.msdn.com/p2p/archive/2007/03/12/writing-peer-to-peer-applications-using-net-part-1-pnrp.aspxI know I keep narrowing it down, but will it be accomplishabe without using the peerToPeer workarround?
Sagi1981
I have now gotten it to work - thank you so much for your help
Sagi1981
A: 

Maybe a UPnP server and client may be a solution to your problem?

Lucero
I will look into this as well - thanks for your reply :)
Sagi1981
Actually, the SSDP protocol used for discovery in UPnP is the same as supported by the PNRP implemented in the System.Net.PeerToPeer namespace, so that should work pretty well and enabling UPnP exception on the firewall should work for it too.
Lucero
If you look at my comment to the other answer.Will UPnP also require PeerToPeer to be enabled, and are there any security risks involved?
Sagi1981
UPnP is not really complicated. So if the component is missing from Windows, you could listen using your own implementation for the server; the client part of SSDP is easy anyways. Just be careful not to have a "collision" with another UPnP server service running on the same machine. There are some plain C# code UPnP samples around, such as http://www.codeproject.com/KB/IP/upnpnattraversal.aspx
Lucero
I am sorry to be bothering again, but I still haven't found the just right solution. UPnP and PeerToPeer isn't really an option for me either. So therefore - is there a way to implement what I state in my initial post, without using UPnP or PeerToPeer, or other windows components, that the user might not have enabled. The only prerequisite we can be absolutely sure of, is .NET 3.5 (or newer). I appreciate your answer, but any more help is appreciated. I would love to get this problem soved so I can get home for today :)
Sagi1981
Well, why not just implement SSDP on a different UDP port and open a firewall exception for it and you're done... I think that they thought of everything you need to be careful about.http://quimby.gnus.org/internet-drafts/draft-cai-ssdp-v1-03.txt
Lucero
can this firewall exception be the same for both the server machines and the client machines? I mean - let's assume I open for UDP traffic on port 11000. Can I then dirrect both my ingoing and outgoing traffic for both server and client machines trough this port?Thanks for the link - reading it now.
Sagi1981
You only need one port.
Lucero
I have now gotten it to work - thank you so much :)
Sagi1981
You're welcome, and thank you for the feedback!
Lucero