简体   繁体   English

如何在Java中获取UDP数据包发送方的本地IP地址

[英]How to get local ip address of UDP packet sender in java

I have coded a ip to ip video chat application using JMF for my brothers school project. 我已经为我的兄弟学校项目使用JMF编写了一个ip to ip视频聊天应用程序。 In which first of all one of the user sends an udp as a chat request to another system. 用户首先从哪个用户向另一个系统发送udp作为聊天请求。 Then the second system sends a reply to the first system after that video chat starts. 然后,第二系统在该视频聊天开始后向第一系统发送回复。 Every thing is working perfectly while there is no router b/W two systems(eg Both are on same lan or connected to internet via usb modem). 当没有路由器黑白两个系统时,一切都可以正常工作(例如,两个都在同一局域网中或通过USB调制解调器连接到互联网)。 else when i retrieve the sender's ip from UDP packet it gives the ip of router through which the sender is connected to internet so when second system replies to the request of chatting the first system never receives the reply. 否则,当我从UDP数据包中检索发送方的ip时,它将给出发送方通过其连接到互联网的路由器的ip,因此,当第二个系统回复聊天请求时,第一个系统永远不会收到回复。 So how can i get the local ip of the UDP sender. 因此,我如何获取UDP发送方的本地IP。

Thanks every one in advance. 预先感谢大家。

You're talking about NAT traversal and it's a really hard problem. 您正在谈论NAT遍历,这是一个非常困难的问题。 There's more on Wikipedia https://en.wikipedia.org/wiki/NAT_traversal . Wikipedia上还有更多内容https://en.wikipedia.org/wiki/NAT_traversal

If it's just for a school project, I would just make it work on a local network and not bother with NAT traversal. 如果仅用于学校项目,我只会使其在本地网络上工作,而不必担心NAT遍历。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM