是否可以通过 TCP 进行广播? [英] Is broadcasting via TCP possible?

查看:27
本文介绍了是否可以通过 TCP 进行广播?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在用 C 编写一个服务器/客户端系统,它在 TCP 连接下使用 BSD 套接字.服务器是多线程的,每个连接都在自己的接收器中运行.每个客户端都在一对一的基础上很好地与服务器交谈,遗憾的是我想不出一种方法来实现 SendToAll() 函数,例如,如果客户端 A 做了一些需要发送数据包的事情所有的客户.我该怎么做?

I'm writing a server/client system in C, which uses BSD Sockets under a TCP connection. The server is multi-threaded, with each connection running in its own receptor. Each client does a good job talking with the server on a one-to-one basis, sadly I can't think of a way to implement a SendToAll() function, for instance, if client A does something that requires sending a packet to all of the clients. How would I do this?

我正在考虑在每个接收器中实现一个队列,并且任何广播都会被发送到这些队列;当接收器发出一个新数据包时,它也会将该消息添加到数据包中,如果这有意义的话.

I was considering implementing a queue in every receptor, and any broadcast gets sent to those queues; when the receptor sends out a new packet, it adds that message onto the packet as well, if that makes any sense.

但是,有没有什么办法可以通过 TCP 进行广播,就像通过 UDP 一样?

But yeah, is there any way to broadcast via TCP, like you can via UDP?

推荐答案

正如大家所说的那样,TCP 不可能实现,它只是单播.但是,有可靠多播的实现,它应该为您提供具有 TCP 可靠性的多播.请参阅维基百科,尤其是实用通用多播.

As everyone has said that is not possible with TCP, it is unicast only. However there are implementations of reliable multicast, which should give you multicast with the reliability of TCP. See wikipedia, especially Pragmatic General Multicast.

这篇关于是否可以通过 TCP 进行广播?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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