質問

I write GateServer to isolate Lan and Internet,Gateserver accept connection and route packet from both side. Suppose if in Lan, PC assigned address 10.0.0.40 and assigned 202.xxx.xxx.xxx on Internet,Can I just listen on INADDR_ANY to recv data from both side?

役に立ちましたか?

解決

Yes. However, since you are doing your own routing between networks, it might make your logic easier to manage if you create separate listening sockets, one bound to only the LAN IP, and the other bound to only the Internet IP. That way, when your code receives a new connection, it will know exactly whether it is a LAN client or an Internet client. If you only listen on one socket on both IPs, you have to manually determine which network each connection comes from.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top