delphi7 udpsocket 怎么用? ( 积分: 30 )

  • 主题发起人 主题发起人 鸢都剑客
  • 开始时间 开始时间

鸢都剑客

Unregistered / Unconfirmed
GUEST, unregistred user!
怎么用UDPSOCKET 发数据啊如
向192.168.0.1 的3000端口发送'aaa'
 
怎么用UDPSOCKET 发数据啊如
向192.168.0.1 的3000端口发送'aaa'
 
UDPSocket.Send('aaaa');
 
procedure TUDPMainForm.FormCreate(Sender: TObject);
begin
HostName.Caption := UDPServer.LocalName;
HostAddress.Caption := GStack.LocalAddress;
Port.Caption := IntToStr(UDPServer.DefaultPort);
BufferSize.Caption := IntToStr(UDPServer.BufferSize);
UDPServer.Active := True;
end;

procedure TUDPMainForm.UDPServerUDPRead(Sender: TObject; AData: TStream; ABinding: TIdSocketHandle);
var
DataStringStream: TStringStream;
s: String;
begin
DataStringStream := TStringStream.Create('');
try
DataStringStream.CopyFrom(AData, AData.Size);
UDPMemo.Lines.Add('Received "' + DataStringStream.DataString + '" from ' + ABinding.PeerIP + ' on port ' + IntToStr(ABinding.PeerPort));
s := 'Replied from ' + UDPServer.LocalName + ' to "' + DataStringStream.DataString + '"';
delay(5000);
ABinding.SendTo(ABinding.PeerIP, ABinding.PeerPort, s[1], Length(s));
finally
DataStringStream.Free;
end;
end;
 
后退
顶部