self-hosted server with CG-NAT problem

David Cole17 days ago

I think you can add

server_socket.settimeout(10)  # Timeout in seconds

before the while True and it should time out in connecting at least - but wont help you if it's not connecting.

But sorry, i really don't know why it's not getting past that line for you.
Mine is in a docker container, and looks like it's python 3.9

I can see this being set as an argument in the Dockerfile : ARG PYTHONUNBUFFERED=0

djmelman17 days ago

Yes it timed out there. I am trying it with Traccar Client on phone and the vps is receiving packets thought the tcpdump command but the script isnt reacting to it

David Cole17 days ago

I just tried echo "CONNECT" | nc localhost 30175 where 30175 is the port the script is listening to and mine responded:

receiving data 376 bytes
receiving data 408 bytes
Data transmitted
Data transmitted
connect
[*]Accepted connection from 172.18.0.1:58752
receiving data 8 bytes
Data transmitted

But I think you found that it's not starting the server. Is there anything in syslog? maybe permissions creating a socket or apparmor or somethign like that getting in the way?

djmelman17 days ago

From localhost its working

Snímka obrazovky 2025-02-06 203957.png

David Cole17 days ago

In your traccar, can you see the connection?

2025-02-07 08:36:26  INFO: [T6e9451c3] connected
2025-02-07 08:36:26  INFO: [T6e9451c3: osmand < 192.168.10.100] CONNECT\n
2025-02-07 08:36:26  INFO: [T6e9451c3: osmand > 192.168.10.100] HTTP/1.1 400 Bad Request\r\ncontent-length: 0\r\n\r\n
2025-02-07 08:36:26  INFO: [T6e9451c3] disconnected

That was me doing an echo "CONNECT" to the script and it's been forwared to traccar. I can't remember the actual command I need to set a device online with the OSMND protocol.

djmelman17 days ago

In the traccar i see connected disconnected thats because the nc is just empty but the problem is somewhere on the vps cause when i tried the nc command from other device like "nc 'publicIPofVPS' 5055" nothing happened

David Cole17 days ago

So i looked at my ingress rules, I don't allow source of 0.0.0.0, but I restrict it to a pretty high level for the mobile network my device will connect to.

Did you fire "CONNECT" or some actual tcp data and pick that up in traccar? I think the script by default connects and disconnects all the time. You want to see, like mine a bad request listed by traccar, to verify the script actually picked up the tcp command you fired.

David Cole17 days ago

maybe try instead of listening on 0.0.0.0 to listen on the actual external ip of the VM?
https://www.reddit.com/r/learnpython/comments/75fwyt/trying_to_write_a_simple_socket_server_stuck_at/

djmelman17 days ago

I didnt actually. Oracles machine died now. Thanks for your help maybe ill try it again sometime or just pay my provider for public ip

djmelman17 days ago

Umm it might actually be it. cause on my intefaces there was only private ip and it was natting it but when u listen on 0.0.0.0 it might just listen on the private IP ? idk

djmelman17 days ago

One more question do you have internet gateway setup in the oracle cloud with ur subnet that vps is in?

David Cole17 days ago

not sure. Dont think so, the set up is pretty limited. Just the ingress rules. I onlty have the networks pages and VM page pinned - meaning I don't tend to look around too far.