感谢大家的关心,下面是部分代码
客户机
procedure TClient.CUDPDataReceived(Sender: TComponent;
NumberBytes: Integer; FromIP: String; Port: Integer);
var
CtrlCode:array[0..29] of char;
Buf:array[0..BufSize-1] of char;
TmpStr:string;
SendSize,LeftPos,TopPos,RightPos,BottomPos:integer;
begin
CUDP.ReadBuffer(CtrlCode,NumberBytes);//读取控制码
if CtrlCode[0]+CtrlCode[1]+CtrlCode[2]+CtrlCode[3]='show' then
begin
if BmpStream.Size=0 then//无数据,必须截屏
........
ScreenCap(LeftPos,TopPos,RightPos,BottomPos);//截屏
end;
if LeftSize>BufSize then
SendSize:=BufSize
else
SendSize:=LeftSize;
BmpStream.ReadBuffer(buf,sendSize);
LeftSize:=LeftSize-SendSize;
if LeftSize=0 then BmpStream.Clear;//清空流
CUDP.RemoteHost:='1.0.0.53';//FromIP 是主控机IP地址
CUDP.SendBuffer(Buf,SendSize);//发数据到主控机的2222口
end;
服务器
procedure Tserver.SUDPDataReceived(Sender: TComponent;
NumberBytes: Integer; FromIP: String; Port: Integer);
var
ReqCode:array[0..29] of char;
ReqCodeStr:String;
begin
ReqCodeStr:='show'+Edit1.Text;
StrpCopy(ReqCode,ReqCodeStr);
SUDP.ReadStream(TmpStream);
RsltStream.CopyFrom(TmpStream,NumberBytes);
if NumberBytes<BufSize then//数据已读完
begin
Rsltstream.Position:=0;
image1.Picture.Bitmap.LoadFromStream(RsltStream);
TmpStream.Clear;
RsltStream.Clear;
end
else
begin
TmpStream.Clear;
ReqCode:='show';
SUDP.RemoteHost:=Edit1.Text;
SUDP.SendBuffer(ReqCode,30);
end;
end;
procedure Tserver.BitBtn1Click(Sender: TObject);
var
ReqCode:array[0..29] of char;
ReqCodeStr:String;
begin
ReqCodeStr:='show'+Edit1.Text;
StrpCopy(ReqCode,ReqCodeStr);
TmpStream.Clear;
RsltStream.Clear;
SUDP.RemoteHost:=Edit2.Text;
SUDP.SendBuffer(ReqCode,30);
end;