开发无服务器 LAN 聊天程序帮助!

发布于 2024-07-10 19:44:45 字数 215 浏览 7 评论 0原文

我想开发简单的无服务器局域网聊天程序只是为了好玩。 我怎样才能做到这一点 ? 我应该使用什么类型的架构?

去年我参与了 TCP,UDP 客户端/服务器应用程序项目。它很简单(服务器侦听某些端口/套接字,客户端连接到服务器的端口等。)但我不知道如何开发“无服务器”局域网聊天程序。 我怎样才能做到这一点? UDP、TCP、组播、广播? 或者程序的行为应该像服务器和客户端一样吗?

I want to develop simple Serverless LAN Chat program just for fun. How can I do this ? What type Architecture should I use?

Last year I have worked on TCP,UDP Client/ Server application Project.It was simple (Server listens to certain port/socket and Client connect to server's port etc..) But I have no idea about how to develop "Serverless" LAN Chat program. How can I do this? UDP,TCP,Multicast,Broadcast? or Should program behave like both server and client?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

和我恋爱吧 2024-07-17 19:44:45

最简单的方法是使用 UDP 并在整个网络上广播您的消息。
更高级的版本是仅使用广播来发现网络中的其他节点。

  • 每个节点都维护一个已知对等点的列表。
  • 消息通过 TCP 发送到所有已知的对等点。
  • 当节点启动时,它会发出 UDP 广播来发现其他节点。
  • 当节点接收到发现广播时,它会将“自己”发送到广播源,以使其自身为人所知。 接收节点将广播者添加到它自己的已知对等点列表中。
  • 当节点退出网络时,它会发送另一个广播,以通知其余节点应将已删除的客户端从列表中删除。

您还必须考虑处理节点的退出,而不让它们通知网络的其余部分。

The simplest way would be to use UDP and simply broadcast your messages all over the network.
A little bit more advanced version would be to only use the broadcast to discover other nodes in the network.

  • Every node maintains a list of known peers.
  • Messages are sent with TCP to all known peers.
  • When a node starts up, it sends out an UDP broadcast to discover other nodes.
  • When a node receives a discovery broadcast, it sends "itself" to the source of the broadcast, in order to make it self known. The receiving node adds the broadcaster to it's own list of known peers.
  • When a node drops out of the network, it sends another broadcast in order to inform the remaining nodes that they should remove the dropped client from their list.

You would also have to consider handling the dropping out of nodes without them informing the rest of the network.

辞慾 2024-07-17 19:44:45

spread 工具包对于你想要的东西来说可能有点大材小用,但却是一个有趣的起点。

从简介中可以看出:


Spread 是一个开源工具包,它提供高性能的消息传递服务,能够适应局域网和广域网的故障。 Spread 充当分布式应用程序的统一消息总线,并提供高度调整的应用程序级多播、组通信和点对点支持。 传播服务范围从可靠的消息传递到具有交付保证的完全有序的消息。

Spread 可用于许多需要高可靠性、高性能以及各个成员子集之间强大通信的分布式应用程序。 该工具包旨在封装异步网络的挑战性方面,并支持构建可靠且可扩展的分布式应用程序。

Spread 由一个与用户应用程序链接的库、一个在属于处理器组的每台计算机上运行的二进制守护程序以及各种实用程序和演示程序组成。

Spread 提供的一些服务和优势:

  • 可靠且可扩展的消息传递和群组通信。
  • 一个非常强大但简单的API简化了分布式架构的构建。
  • 易于使用、部署和维护。
  • 从单一局域网到复杂的广域网具有高度可扩展性。
  • 支持数千个具有不同成员组的群组。
  • 在出现机器故障、进程崩溃和恢复以及网络分区和合并的情况下实现消息可靠性。
  • 为消息提供一系列可靠性、有序性和稳定性保证。
  • 强调稳健性和高性能。
  • 完全分布式算法,没有中心故障点。

The spread toolkit may be a bit overkill for what you want, but an interesting starting point.

From the blurb:


Spread is an open source toolkit that provides a high performance messaging service that is resilient to faults across local and wide area networks. Spread functions as a unified message bus for distributed applications, and provides highly tuned application-level multicast, group communication, and point to point support. Spread services range from reliable messaging to fully ordered messages with delivery guarantees.

Spread can be used in many distributed applications that require high reliability, high performance, and robust communication among various subsets of members. The toolkit is designed to encapsulate the challenging aspects of asynchronous networks and enable the construction of reliable and scalable distributed applications.

Spread consists of a library that user applications are linked with, a binary daemon which runs on each computer that is part of the processor group, and various utility and demonstration programs.

Some of the services and benefits provided by Spread:

  • Reliable and scalable messaging and group communication.
  • A very powerful but simple API simplifies the construction of distributed architectures.
  • Easy to use, deploy and maintain.
  • Highly scalable from one local area network to complex wide area networks.
  • Supports thousands of groups with different sets of members.
  • Enables message reliability in the presence of machine failures, process crashes and recoveries, and network partitions and merges.
  • Provides a range of reliability, ordering and stability guarantees for messages.
  • Emphasis on robustness and high performance.
  • Completely distributed algorithms with no central point of failure.
秋日私语 2024-07-17 19:44:45

Apple 的 iChat 正是您所设想的产品的一个例子。 它使用 Bonjour(苹果的零配置网络协议)来识别 LAN 上的对等点。 然后您可以与他们聊天或音频/视频聊天。

我不完全确定 Bonjour 内部是如何工作的,但我知道它使用多播。 客户端在 LAN 上“注册”服务,Bonjour 协议允许每个主机为给定服务提取主机目录(所有这些都无需集中管理)。

Apples iChat is an example of the very product you are envisioning. It uses Bonjour (apple's zero-conf networking protocol) to identify peers on a LAN. You can then chat or audio/video chat with them.

I'm not entirely sure how Bonjour works inside, but I know it uses multicast. Clients "register" services on the LAN, and the Bonjour protocol allows for each host to pull up a directory of hosts for a given service (all without central management).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文