nodemcu / nodemcu-firmware

Lua based interactive firmware for ESP8266, ESP8285 and ESP32
https://nodemcu.readthedocs.io
MIT License
7.64k stars 3.12k forks source link

Feature Request: Local socket Information #1363

Closed sebcologne closed 7 years ago

sebcologne commented 8 years ago

Missing feature

There is no way to get the receiving port-number of a tcp socket. Basically a getpeer() function, that returns the sockets local port. See an example in python:https://docs.python.org/2/library/socket.html#socket.socket.getsockname

Justification

NAT traversal in a DS-Lite network with unsymmetric NATs (Hole Punching). You need the receiving port number to set up a new server that listens on that port for incoming connections, which are going through the "hole".

Why you ask? Well, a popular German internet provider does not include a publicly accessible IPv4-adress to your sweet high-speed fiber connection. Instead you share your IPv4 adress with a bunch of other people. A cheap way to eliminate this Problem is to use (preferrably TCP) Hole-Punching. ( Or use IPv6 with Devices that support it).

Also because I feel like a mad hacker every time I punch holes through Firewalls...

Workarounds

Polling Data frequently from your server....

djphoenix commented 7 years ago

As in current dev docs, after my work on net module there is getaddr method for socket.

I think we may close it (so add 2.0.0 milestone because currently changes are in dev only)

/cc @marcelstoer

marcelstoer commented 7 years ago

Thanks Yury!