【发布时间】:2017-06-28 23:20:26
【问题描述】:
我正在使用 Delphi 10.0 Seattle。
我想向 UDP 服务器发送请求,然后读取服务器响应,这是一个简单的字符串:
Client side:send('12345')
server side(onread event or whatever):if received string = ('12345') then
send ('jhon|zack|randy')
else disconnect;
响应字符串的长度是可变的。
服务器正在一个开放连接的网络上运行(专用 vps)。 客户端不一样,它在路由器和安全网络后面(不转发)。
到目前为止,我只能从客户端发送请求:
(uc=idUDPclient)
procedure TForm1.Button1Click(Sender: TObject);
var
s:string;
begin
if uc.Connected =False then
Uc.Connect;
uc.Send('12345');
uc.ReceiveTimeout := 2000;
s:=uc.ReceiveString() ;
ShowMessage(s);
uc.Disconnect
end;
服务器端(us=idUDPserver)
procedure TForm1.usUDPRead(AThread:TIdUDPListenerThread;const AData: TIdBytes;ABinding: TIdSocketHandle);
begin
ShowMessage(us.ReceiveString());
if us.ReceiveString() = '12345' then
begin
ShowMessage(us.ReceiveString());
//respond with a string to the client immediately (behind a routers) how ?
end;
不知道TCP是否更好,如何使用。
Android 将参与其中。
【问题讨论】:
标签: delphi udp indy delphi-10-seattle