I am currently working on a simple file transfer application, I would like the receiving end to be able to punch a whole through the router using upnp to accept the connection, my reason for this is to make it easer for the average user, of course they may not know how to manually forward ports.
I am using the IUPnPNAT COM interface witch i looked up from the msdn libary. the problem i am getting is around the Add() function.
When it comes to this part of the code, it locks up. I then realised that ports (TCP "2869" & UDP "1900") have to be opened on the windows firewall to be able to communicate with the router. I then tried to open these ports using the "Windows firewall API" but had no luck. For some strange reason i cannot open or close these ports unless the UPnP Framwork is enabled. When the framwork is enabled the ports are open by default and the application forwards the port "29000" without fail. The problem i am faced with now is i cant keep that framework enabled. so i thought i would try a cheeky system call to enable the framework and disable it once the program has finished etc.
system("netsh firewall set service type = upnp mode = enable");
// Forward port, create a socket accept and recv the file etc.
system("netsh firewall set service type = upnp mode = disable");
When using this method another problem occurs. The first time you run the application, it locks up again when it comes to forwarding the port. but the second time you execute the program the port forwards without fail. it seems that its trying to forward the port before the framework is ready. If anyone out there can help me with this or mention any other methods i can get round this i will be very grateful. i am a self taught and coding is my hobby :-)
Last edited by RipRage; August 29th, 2010 at 10:13 AM.