Indy控件高手请进。关于Indy UDP收到信息的。

DinkyYeung 2004-05-08 08:09:21
我想使用发IndyUDP来发信息,信息可以包含图形所以要使用流来发送

发送流,我使用这样
procedure TFSendMsg.SendMsg;
var
i: integer;
ReceList, ReceFlagList: TStrings;
SendStream: TMemoryStream;
ABuffer: Pointer;
begin
ReceList := TStringList.Create;
ReceFlagList := TStringList.Create;
GetReceList(ReceList, ReceFlagList);

SendStream := TMemoryStream.Create;
MsgContext.Lines.SaveToStream(SendStream);



GetMem(ABuffer, SendStream.Size);
SendStream.Seek(0, soFromBeginning);
SendStream.ReadBuffer(ABuffer^, SendStream.Size);

for i := 0 to ReceList.Count - 1 do
begin
case StrToInt(ReceFlagList[i]) of
UT_WORKGROUP: //到整个工作组
begin
end;
UT_USER: //用户
begin
IdUDPC.Host := ReceList[i];
IdUDPC.SendBuffer(ABuffer^, SendStream.Size); // SizeOf(ABuffer));
end;
end;
end;
SendStream.Free;
SetHint(IS_MSGSENDED);
//DKComm.ShowInfo(IS_MSGSENDED);
end;

接收流信息这样
procedure TFMainForm.IdUDPSUDPRead(Sender: TObject; AData: TStream;
ABinding: TIdSocketHandle);
var
i: integer;
ReceStream: TMemoryStream;
ABuffer: Pointer;
ActReadSize: Integer;
const
bufSize = 4096;
begin
inherited;

GetMem(ABuffer, AData.Size);
AData.ReadBuffer(ABuffer^, AData.Size);

ReceStream := TMemoryStream.Create;
ReceStream.WriteBuffer(ABuffer^, AData.Size);
MsgContext.Lines.LoadFromStream(AData);
Self.BringToFront;
ReceStream.Free;
end;

我试了很多种方法都不行。应该怎么样,帮帮忙
...全文
92 回复 点赞 打赏 收藏 举报
写回复
回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
相关推荐
发帖
Delphi
加入

4969

社区成员

Delphi 开发及应用
申请成为版主
帖子事件
创建了帖子
2004-05-08 08:09
社区公告
暂无公告