可以绑定()和connect()UDP连接的两端 [英] Can you bind() and connect() both ends of a UDP connection

查看:157
本文介绍了可以绑定()和connect()UDP连接的两端的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在写的点对点的消息队列系统,它必须能够通过UDP进行操作。我可以随便挑一方或其他是服务器,但它似乎并不完全正确,因为两端都发送和从其他接收相同类型的数据。

I'm writing a point-to-point message queue system, and it has to be able to operate over UDP. I could arbitrarily pick one side or the other to be the "server" but it doesn't seem quite right since both ends are sending and receiving the same type of data from the other.

是否可以绑定()和connect()两端,使他们发送/只接收对方的?这似乎是一个很好的对称的方式来做到这一点。

Is it possible to bind() and connect() both ends so that they send/receive only from each other? That seems like a nicely symmetric way to do it.

推荐答案

UDP是无连接的,所以在实际进行某种连接几乎没有意义的操作系统。

UDP is connectionless, so there's little sense for the OS in actually making some sort of connection.

在BSD套接字可以做一个UDP套接字连接,但是这基本上只是将默认的目的地址发送(而不是明确地给予 send_to )。

In BSD sockets one can do a connect on a UDP socket, but this basically just sets the default destination address for send (instead giving explicitly to send_to).

这是一个UDP套接字绑定道出其中输入地址实际上接受的数据包(所有数据包到其它地址被删除)操作系统,无论那种插座。

Bind on a UDP socket tells the OS for which incoming address to actually accept packets (all packets to other addresses are dropped), regardless the kind of socket.

在收到您必须使用recvfrom的识别数据包来自哪个源而来。请注意,如果你想要某种身份验证,然后只使用所涉及的地址是无锁的所有不安全。 TCP连接可以被劫持,赤裸裸的UDP字面上都写满了它的头IP欺骗。您必须添加某种HMAC的

Upon receiving you must use recvfrom to identify which source the packet comes from. Note that if you want some sort of authentication, then using just the addresses involved is as insecure as no lock at all. TCP connections can be hijacked and naked UDP literally has IP spoofing written all over its head. You must add some sort of HMAC

这篇关于可以绑定()和connect()UDP连接的两端的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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