Peep2peer, choose ports for TCP
-
I’m trying to make a peer2peer program which can upload/download several files at the time. But how do I know witch ports to use??? I use one port to send information for commands, file size, and so on….. port 7070. The sender program can use any port but the receiver program may not be able to use that port. How do i resolve that problem????? And remember, there could be 3 or 5 files to send/receive. And how do i deal with firewalls and routers??? Please help.
-
I’m trying to make a peer2peer program which can upload/download several files at the time. But how do I know witch ports to use??? I use one port to send information for commands, file size, and so on….. port 7070. The sender program can use any port but the receiver program may not be able to use that port. How do i resolve that problem????? And remember, there could be 3 or 5 files to send/receive. And how do i deal with firewalls and routers??? Please help.
First of all, Don't Panic :) Basicly what you need to do is pretty simple. First, decide on one port number (for instance 7070 you mentioned), now both peers listen on that port, and both peers know that they are both listening on that port. When Peer A wants to send a file to Peer B, it creates a new socket (do not bind that socket to ANY port) and connects it to Peer B (by the known port). Now- Peer B will receive a 'Connection Request', and creates a new socket to accept the new connection. At this point, Peer A can send asorted information about the file it want to send like size, file name hash etc. and then begin to send the file. Because this is all happening on different sockets than the listening ones, both peers can initiate any additional number of connection as you wish (well not any number of connections but a reasonable one :) ) That's it, note that Peer A can also connect and Request a file from Peer B, the possibilities are endless. I can send you an example project i wrote with all this connection creation working, i will post it with an article, but it will take some time as i'm on a tight schedule now and can't write the article now. Let me know if you want the example. Fade (Amit BS)
-
First of all, Don't Panic :) Basicly what you need to do is pretty simple. First, decide on one port number (for instance 7070 you mentioned), now both peers listen on that port, and both peers know that they are both listening on that port. When Peer A wants to send a file to Peer B, it creates a new socket (do not bind that socket to ANY port) and connects it to Peer B (by the known port). Now- Peer B will receive a 'Connection Request', and creates a new socket to accept the new connection. At this point, Peer A can send asorted information about the file it want to send like size, file name hash etc. and then begin to send the file. Because this is all happening on different sockets than the listening ones, both peers can initiate any additional number of connection as you wish (well not any number of connections but a reasonable one :) ) That's it, note that Peer A can also connect and Request a file from Peer B, the possibilities are endless. I can send you an example project i wrote with all this connection creation working, i will post it with an article, but it will take some time as i'm on a tight schedule now and can't write the article now. Let me know if you want the example. Fade (Amit BS)
Thanks for the reply. Any help would be great. You can send it too kim@web-tech.dk. :) Hubbi