LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   socket problem behind NAT (https://www.linuxquestions.org/questions/programming-9/socket-problem-behind-nat-4175532616/)

webquinty 01-31-2015 11:15 AM

socket problem behind NAT
 
Hello,

I would like to connect to computers using sockets, but between both, there is a NAT.
If a connect directly both computers, the connection is ok. If any computer shutdown and power on again, re-connection is successful.

But with NAT, if some computer go down and restart again, some times, computer can not connect with computer behind NAT.

I see socket options like keep alive but I am not sure how to use.

Any advice?

NevemTeve 01-31-2015 12:06 PM

It is a firewall-configuration problem, google for port-forwarding.
http://portforward.com/english/routers/port_forwarding/

webquinty 01-31-2015 04:54 PM

Hello,

It is not a port-forwaring problem.

Internal PC has 192.168.1.x and external PC has 192.168.5.100 (WAN port has 192.168.5.32).
In NAT Table I have create de follow rule:

external ip external port internal ip internal port
192.168.5.32 8888 192.168.1.20 8888

Now, external PC try to connect with internal PC, then router detect that somebody try to connect using port 8888, and forwaring this connection as rule describe before.


Now, I shutdown internal PC but external PC tell that connection is still alive and no drop it.
If I turn on internal PC, external PC can not reconnect with internal PC because old socket is still alive.

Is there any way to detect if socket is correct?
If a detect that socket is wrong, perhaps I could drop old connection and the try to reconnect.

genss 01-31-2015 06:59 PM

Quote:

Originally Posted by webquinty (Post 5309716)
Is there any way to detect if socket is correct?
If a detect that socket is wrong, perhaps I could drop old connection and the try to reconnect.

implement heartbleed ? (or just ping-pong msgs)

NevemTeve 02-01-2015 12:04 AM

If you want to use TCP.KEEPALIVE then use setsockopt(SOL_SOCKET,SO_KEEPALIVE)


All times are GMT -5. The time now is 02:11 PM.