W
wengyz
Unregistered / Unconfirmed
GUEST, unregistred user!
我用socket控件进行局域网图象传输.用陈经韬大侠抓屏幕代码时,
server端已经确认图像流已经发出,
可是client端毫无反应,传text就没问题。用我自己的抓图代码就没问题,
不知道我的问题出在那里了,请高手帮忙,谢谢.
代码如下:
server端
procedure TClient.ServerSocket1ClientRead(Sender: TObject;
Socket: TCustomWinSocket);
var
Buf:array[0..BufSize-1] of char;
TmpStr:string;
SendSize,LeftPos,TopPos,RightPos,BottomPos:integer;
MyBmp: TBitmap;
Myjpg: TJpegimage;
begin
TmpStr := Socket.ReceiveText;
if copy(tmpstr,0,4)='show' then
begin { 控制码前4位为“show”表示主控机发出了抓屏指令 }
BmpStream:=TMemoryStream.Create;
TmpStr:=Copy(TmpStr,5,Length(TmpStr)-4);
LeftPos:=StrToInt(Copy(TmpStr,1,Pos(':',TmpStr)-1));
TmpStr:=Copy(TmpStr,Pos(':',TmpStr)+1,Length(TmpStr)
-Pos(':',TmpStr));
TopPos:=StrToInt(Copy(TmpStr,1,Pos(':',TmpStr)-1));
TmpStr:=Copy(TmpStr,Pos(':',TmpStr)+1,Length(TmpStr)-
Pos(':',TmpStr));
RightPos:=StrToInt(Copy(TmpStr,1,Pos(':',TmpStr)-1));
BottomPos:=StrToInt(Copy(TmpStr,Pos(':',TmpStr
)+1,Length(TmpStr)-Pos(':',TmpStr)));
// ScreenCap(LeftPos,TopPos,RightPos,BottomPos); //我的抓图代码
MyBmp := TBitmap.Create;
Myjpg := TJpegimage.Create;
Cjt_GetScreen(MyBmp, True); //陈经韬大侠抓屏幕代码
Myjpg.Assign(MyBmp);
Myjpg.CompressionQuality := 10;
Myjpg.SaveToStream(BmpStream);
Myjpg.free;
MyBmp.free;
LeftSize := BmpStream.Size;
Socket.SendText(inttostr(LeftSize));
end
else
begin
Socket.SendStream(BmpStream);
end;
end;
client:
procedure TServer.ClientSocket1Read(Sender: TObject;
Socket: TCustomWinSocket);
var
MyBuffer: array[0..100000] of byte;
MyReceviceLength: integer;
MyBmp: TBitmap;
MyJpg: TJpegimage;
begin
if flag = 0 then
begin
bmpsize :=strtoint(Socket.ReceiveText);
Image1.Picture.Bitmap.FreeImage;
if bmpsize >0 then
begin
flag :=1;
Socket.SendText( 'aa');
end;
end
else
begin
MyReceviceLength :=Socket.ReceiveLength;
Socket.ReceiveBuf(MyBuffer,MyReceviceLength);
RsltStream.Write(MyBuffer,MyReceviceLength);
if RsltStream.Size >= Bmpsize then
begin
RsltStream.Position:=0;
MyJpg := tjpegimage.Create;
mybmp := TBitmap.Create;
MyJpg.LoadFromStream(RsltStream);
MyBmp.Assign(MyJpg);
Image1.Picture.Bitmap.Assign(MyBmp);
flag := 0;
RsltStream.Clear;
Socket.SendText('show'+Edit1.Text);
i := i+1;
RichEdit1.Text := inttostr(i);
end;
end;
end;
server端已经确认图像流已经发出,
可是client端毫无反应,传text就没问题。用我自己的抓图代码就没问题,
不知道我的问题出在那里了,请高手帮忙,谢谢.
代码如下:
server端
procedure TClient.ServerSocket1ClientRead(Sender: TObject;
Socket: TCustomWinSocket);
var
Buf:array[0..BufSize-1] of char;
TmpStr:string;
SendSize,LeftPos,TopPos,RightPos,BottomPos:integer;
MyBmp: TBitmap;
Myjpg: TJpegimage;
begin
TmpStr := Socket.ReceiveText;
if copy(tmpstr,0,4)='show' then
begin { 控制码前4位为“show”表示主控机发出了抓屏指令 }
BmpStream:=TMemoryStream.Create;
TmpStr:=Copy(TmpStr,5,Length(TmpStr)-4);
LeftPos:=StrToInt(Copy(TmpStr,1,Pos(':',TmpStr)-1));
TmpStr:=Copy(TmpStr,Pos(':',TmpStr)+1,Length(TmpStr)
-Pos(':',TmpStr));
TopPos:=StrToInt(Copy(TmpStr,1,Pos(':',TmpStr)-1));
TmpStr:=Copy(TmpStr,Pos(':',TmpStr)+1,Length(TmpStr)-
Pos(':',TmpStr));
RightPos:=StrToInt(Copy(TmpStr,1,Pos(':',TmpStr)-1));
BottomPos:=StrToInt(Copy(TmpStr,Pos(':',TmpStr
)+1,Length(TmpStr)-Pos(':',TmpStr)));
// ScreenCap(LeftPos,TopPos,RightPos,BottomPos); //我的抓图代码
MyBmp := TBitmap.Create;
Myjpg := TJpegimage.Create;
Cjt_GetScreen(MyBmp, True); //陈经韬大侠抓屏幕代码
Myjpg.Assign(MyBmp);
Myjpg.CompressionQuality := 10;
Myjpg.SaveToStream(BmpStream);
Myjpg.free;
MyBmp.free;
LeftSize := BmpStream.Size;
Socket.SendText(inttostr(LeftSize));
end
else
begin
Socket.SendStream(BmpStream);
end;
end;
client:
procedure TServer.ClientSocket1Read(Sender: TObject;
Socket: TCustomWinSocket);
var
MyBuffer: array[0..100000] of byte;
MyReceviceLength: integer;
MyBmp: TBitmap;
MyJpg: TJpegimage;
begin
if flag = 0 then
begin
bmpsize :=strtoint(Socket.ReceiveText);
Image1.Picture.Bitmap.FreeImage;
if bmpsize >0 then
begin
flag :=1;
Socket.SendText( 'aa');
end;
end
else
begin
MyReceviceLength :=Socket.ReceiveLength;
Socket.ReceiveBuf(MyBuffer,MyReceviceLength);
RsltStream.Write(MyBuffer,MyReceviceLength);
if RsltStream.Size >= Bmpsize then
begin
RsltStream.Position:=0;
MyJpg := tjpegimage.Create;
mybmp := TBitmap.Create;
MyJpg.LoadFromStream(RsltStream);
MyBmp.Assign(MyJpg);
Image1.Picture.Bitmap.Assign(MyBmp);
flag := 0;
RsltStream.Clear;
Socket.SendText('show'+Edit1.Text);
i := i+1;
RichEdit1.Text := inttostr(i);
end;
end;
end;