在Delphi中发送和接收数据流 [英] Sending and receiving data streams in Delphi

查看:598
本文介绍了在Delphi中发送和接收数据流的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

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

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

连接可能如下所示


  1. 任何数据都可能丢失;

  2. ,但其余部分必须按时到达,并且延迟尽可能短(最多2秒);

  3. 可以将延迟的数据视为丢失,可以

我认为它可能类似于视频会议软件,但仅使用简单的文本作为数据。

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


  • 什么样的组件可以我使用(任何INDY示例);

  • 您推荐什么技术。

我有计划与Delphi一起使用,但也欢迎其他建议。

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

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

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

是否可以通过流发送图像

Is it possible to send images through the stream

推荐答案

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

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.

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

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.

更新

实施非常简单:

发送数据:

将TIdUDPClient拖放到窗体上。将主机设置为接收端的名称或IP地址(如果在同一台计算机上运行程序,则设置为 localhost),将端口设置为服务器正在侦听的高编号,例如54656。

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!');

接收数据:

Drop TIdUDPServer组件在表格上。将默认端口设置为与发送应用程序相同的端口。添加OnUDPRead事件处理程序,代码如下:

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.

更新2

UDP对于图像不是很好,如果要确保它们不会损坏,除非图片非常小,可以放入一个小包。

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.

这篇关于在Delphi中发送和接收数据流的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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