Ace128 has asked for the wisdom of the Perl Monks concerning the following question:

Hey,

Im working on a simple server/client application in Perl to ease transfering files between 2 persons. Im using Tk and Net::EasyTCP. A direct peer to peer connection is rather simple. But, problem accures when the persons are behind some kind of router or simular. I suspect it works nicely for messenger apps like msn and skype since they connect to a server first...
user#1 user#2 (local ip like: 192.168.0.34) (192.168.0.54) | | | router/proxy router/proxy | | Internet Internet \ / ------- ------- | | Server Pic 1.
and somehow the server redirects the data... (anyone know if the data send between the users goes through the server aswell or some kind of direct connection is created by server between the users? If so, how to do that?)

It seems to me that having some kind of server is quite the only way to make it possible to connect 2 users that are behind the internet by some router/proxy shown in Pic 1. But how do one take 2 sockets and join them (pipeing)?

Or, even better, its possible to join two users some way else? Basicly, Im trying to make the process 2 peers connect without too much hassle. Some folks don't even know what a FTP server is (yet install and use one), so I thought I create this "simple" tool. Just enter ip/dns and port to connect to. Where the other dude has the "server" running... Yes, one can use the messenger apps, but its too much work, if you wanna send many files... and I get rather slow speeds with them sometimes (so it does go through the server?).

I also suppose that the dude running the server may have to have port forwarding...

(Yea, sorry, not too much Perl related, although I do this in Perl)

Thanks,
Ace

Replies are listed 'Best First'.
Re: A Simple Server/Client implementation
by acid06 (Friar) on Mar 06, 2006 at 23:13 UTC
    If these two users are behind broadband routers you can try asking the router to forward a port using Universal Plug and Play.
    There's even a module at the CPAN for it: Net::UPnP.

    Through UPnP is how file sharing applications and other peer-to-peer application can correctly work behind NAT layers.

    Unfortunately, I don't know if corporate routers support it - I suppose they don't.
    But pretty much every broadband router, wifi access points, etc, supports UPnP nowadays.


    acid06
    perl -e "print pack('h*', 16369646), scalar reverse $="
      Hmm, interesting... Gotta check that module... Thanks.

      UPDATE: Well well.. runing the example mentioned in the module gives nothing... on reading some more about this on the webb...
        Specifically, you should look at Net::UPnP::GW::Gateway.
        This is the UPnP device that represents an internet gateway.


        acid06
        perl -e "print pack('h*', 16369646), scalar reverse $="