如何使用udp协议进行通信 [英] How to make the communicate using udp protocol

查看:160
本文介绍了如何使用udp协议进行通信的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





我需要在两台计算机之间进行通信。

一个是互联网,一台机器是局域网。



互联网机器无法访问lan机器目录。

但lan机器可以访问该互联网机器,



是否有可能在这两台机器之间共享udp pkts。

解决方案

这取决于您的LAN如何连接到互联网。将LAN连接到Internet的路由器使用NAT(网络地址转换)时,必须为路由器上的传入数据包设置端口转发。这还要求互联网上的计算机知道路由器的公共(互联网端)IP地址。如果这可能会改变(就像大多数拨号和非商业连接一样),您还必须使用动态DNS服务。



如果这是针对公司的,问网络管理员。否则,请参阅路由器的文档,并在必要时阅读有关端口转发和动态DNS的信息。



一般来说,这更像是一个网络主题而非编程主题。


如果两台机器都知道彼此的IP地址,我会使用TCP / IP协议而不是UDP。 UDP只是一种广播:
(文档)
UDP是无连接协议。当您发送数据或消息时,您不知道它是否会到达那里,它可能会在路上丢失。传输邮件时可能存在损坏。

在其他情况下(IP未知),您可以尝试使用UDP。看一下这个例子,开始吧:



http ://www.abc.se/~m6695/udp.html


hi,

i need to make communication between two computers.
one is in internet one machine is in lan.

internet machine can''t access the lan machine directory.
but lan machine can able to access that internet machine,

Is any possibility is there to share the udp pkts between these two machines.

解决方案

This depends on how your LAN is connected to the internet. When the router that connects your LAN to the internet uses NAT (Network Address Translation), you must setup port forwarding for incoming packets on your router. This requires also that the computer on the internet knows the public (internet side) IP address of your router. If this may change (like with most dial-up and non-commercial connections), you must also use a dynamic DNS service.

If this is for a company, ask the network administrator. Otherwise, see the documentation of your router and read about Port Forwarding and dynamic DNS if necessary.

In general this is more a networking topic than a programming one.


If both of machines knows the IP address of each other I would use TCP/IP protocol rather then UDP. UDP is just a kind of broadcasting:
 (Documentation)
UDP is connectionless protocol. When you a send a data or message, you don't know if it'll get there, it could get lost on the way. There may be corruption while transferring a message.

In other case (the IPs are not known) you can try it with UDP. Take a look at this example for start with it:


http://www.abc.se/~m6695/udp.html


这篇关于如何使用udp协议进行通信的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆