Delphi中发送和接收数据流

发布于 2024-12-11 01:30:59 字数 462 浏览 0 评论 0原文

我想创建一个软件来连接到另一个程序并通过互联网将一些数据(基于文本)发送到另一个程序。

软件将每 300 毫秒发送一次数据(使用定时器),接收器必须按时接收数据。

连接可能如下所示,

  1. 任何数据都可能丢失;
  2. 但其余人员必须准时到达,并尽可能减少延误(最多 2 秒);
  3. 延迟的数据可视为丢失,可以忽略。

我想它可能类似于一个视频会议软件,只不过只是使用简单的文本作为数据。

谁能告诉我如何制作这样一个程序,具体来说

  • 我可以使用什么样的组件(任何 INDY 示例);
  • 您推荐哪些技术。

我计划用 Delphi 来做,但也欢迎其他推荐。

==========================update1 =================

是否可以发送图片穿过溪流

I want to create a software to connect to another and send some data (text based) to another program through the internet.

The software will send data every 300 milliseconds (using timer) and the receiver must receive the data on time.

The connection can be like the following

  1. any data can be lost;
  2. but the rest must arrive on time with minimum delay as possible (maximum 2 seconds);
  3. the delayed data can be considers as lost, can be ignored.

I think it may be similar to a video conference software, but only using simple text as data.

Can anyone tell me how to make such a program, specifically

  • what kind of component can I use (any INDY examples);
  • what technologies do you recommend.

I have planned to do it with Delphi but other recommendation also welcome .

==========================update1 =================

Is it possible to send images through the stream

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

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

发布评论

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

评论(2

旧城烟雨 2024-12-18 01:30:59

我建议使用 UDP 协议并向数据添加时间戳信息并跟踪接收端的传入数据。您可以使用 Indy 或其他软件包中的 UDP 服务器 (TIdUDPServer) 和客户端 (TIdUDPClient) 组件。客户端组件用于发送数据,服务器组件用于接收数据。

就我个人而言,我通常更喜欢 Synapse 类。它们的级别比 Indy 低,因此更容易知道发生了什么,但另一方面,您可能需要自己实现 Indy 默认提供的东西。

更新

实现非常简单:

发送数据:

将 TIdUDPClient 放在表单上。将“Host”设置为接收端的名称或IP地址(如果您在同一台计算机上运行程序,则为“localhost”)并将端口设置为服务器侦听的高编号,例如54656。

将以下代码添加到按钮或计时器事件:

IdUDPClient1.Send('Hello, world!');

接收数据:

将 TIdUDPServer 组件拖放到窗体上。将默认端口设置为与发送应用程序中相同的端口。添加 OnUDPRead 事件处理程序,代码为:

MessageDlg('Received: ' + StringOf(AData), mtInformation, [mbOk], 0);

每次收到新消息时都会弹出新消息对话框。

更新 2

UDP 不适用于图像,如果您想确保图像不被损坏,除非图像非常小并且适合一个数据包。

I suggest using UDP protocol and adding timestamp information to your data and track incoming data on the receiving end. You can use UDP server (TIdUDPServer) and client (TIdUDPClient) components from Indy or other packages. Client component is for sending data and server for receiving.

Personally I usually prefer Synapse -classes. They are lower level than Indy, so it's easier to know what's happening but on the otherhand you may need to implement something yourself what Indy may provide by default.

Update

Implementation is pretty straight forward:

Sending data:

Drop TIdUDPClient on the form. Set "Host" to name or IP address of receiving end (or "localhost" if you run your programs in same computer) and port to high number where server is listening, eg 54656.

Add following code to button or timer event:

IdUDPClient1.Send('Hello, world!');

Receiving data:

Drop TIdUDPServer component on the form. Set default port to same port as in sending application. Add OnUDPRead event handler, with code:

MessageDlg('Received: ' + StringOf(AData), mtInformation, [mbOk], 0);

And new message dialog pops up everytime new message is received.

Update 2

UDP is not good for images, if you want to be sure they will stay uncorrupted, unless the image is very small and fits inside one packet.

我的奇迹 2024-12-18 01:30:59

我建议使用除 Indy 之外的任何东西。它存在缺陷(特别是与 Delphi 捆绑的版本)并且比其他组件集慢。它很容易理解并开始使用它,但是一旦您深入研究底层,您就会开始注意到一些小问题。 Indy 一直在开发中,您可以此处找到最新版本。问题是,由于一些硬编码的依赖关系,您无法轻松地将捆绑版本替换为 2009 年以后的 Delphi 版本中的更新版本。

Delphi 几乎没有集成其他网络通信方法,但我建议探索第 3 方组件。首先,如果你想要开源,你应该看看Overbyte ICS。它有点难以掌握,但它具有良好的性能和功能集。

作为一个非常好的商业解决方案,请查看IP^Works。我只是初步了解了它,但从我所看到的来看,我可以全心全意地推荐它。

I'd recommend using anything but Indy. It is both buggy (especially versions bundled with Delphi) and slower than other component sets. It is easy to understand and start using it, but once you delve deeper under the hood, you start noticing small problems. Indy is constantly under development and you can find latest build here. Problem is that you can't easily replace the bundled version with newer in Delphi versions from 2009 onward because of some hard-coded dependencies.

Delphi has few other network communication methods integrated, but I recommend exploring 3rd party components. First, if you want open source, you should take a look at Overbyte ICS. It is a bit difficult to master, but it has good performance and feature set.

As a very good commercial solution, take a look at IP^Works. I have only scratched it, but from what I saw, I can wholeheartedly recommend it.

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