ARTICLE AD BOX
Can someone help me create a chat and file transfer system using sockets? I tried it, but it didn't work. From what I found, it requires manual port forwarding. I also read that I can use miniupnpc to solve this problem, but I am not sure how to write the code with it, especially for file transferring.
From what I understand, we need to add the UPnP mapping at the start and remove it when the application ends. However, I am confused about where to put my internal or external IP address when adding the port mapping using miniupnpc. Can someone help me write the code?
I found this example:
import miniupnpc upnp = miniupnpc.UPnP() upnp.discoverdelay = 10 upnp.discover() upnp.selectigd() port = 43210 # addportmapping(external-port, protocol, internal-host, internal-port, description, remote-host) upnp.addportmapping(port, 'TCP', upnp.lanaddr, port, 'testing', '')Simple example for miniupnp. It creates a mapping on the discovered gateway from external port 43210 to the interface connected to port 43210 on the interface connected to the discovered gateway.
But when someone connects externally to me, should I use the internal port or the external port?
Imagine this situation:
Server
Internal IP: 127.0.0.1
Internal port: 500
Protocol: TCP
External IP: 195.234.03.12
External port: 500
Client
Internal IP: 127.0.0.1
Internal port: 500
Protocol: TCP
External IP: 205.105.203.1
External port: 500
I need to understand what the value i need to put on this command. I am putting my effort into using miniupnpc, like this:
upnp.addportmapping(500, 'TCP', 127.0.0.1, 500, 'Socket', 195.234.03.12)