胡
胡一刀007
Unregistered / Unconfirmed
GUEST, unregistred user!
我在用SendBuffer发送后,在接收时总是会自动退出,为什么?
接收时的代码为:
procedure TchatForm.ServerSocketClientRead(Sender: TObject;
Socket: TCustomWinSocket);
var
RecLength:integer;
TotalByteArr:Array of byte;
I:integer;
TempStr:String;
Socketjpg: TJpegImage;
SocketBmp: TBitmap;
m:tmemorystream;
begin
SocketStatusBar.Panels[0].Text:='客户端'+Socket.RemoteHost+'正在读信息...';
Showmessage('step1');
RecLength:=Socket.ReceiveLength;
Showmessage('step2');
SetLength(TotalByteArr,RecLength);
Showmessage('step3');
Socket.ReceiveBuf(TotalByteArr,RecLength);
Showmessage('step4');
Memo2.Lines.Add(InttoStr(RecLength));
Showmessage('step5');
m.Write(TotalByteArr,RecLength); <----就是这句话出错了!为什么?好象读不出TotalByteArr。但RecLength却是正确的,为什么?
Showmessage('step6');
m.Position:=0;
Socketbmp := TBitmap.Create;
Socketbmp.LoadFromStream(m);
Socketbmp.SaveToFile('c:/MySocket.jpg');
Showmessage('step6');
Socketbmp.Free;
。。。。
end;
接收时的代码为:
procedure TchatForm.ServerSocketClientRead(Sender: TObject;
Socket: TCustomWinSocket);
var
RecLength:integer;
TotalByteArr:Array of byte;
I:integer;
TempStr:String;
Socketjpg: TJpegImage;
SocketBmp: TBitmap;
m:tmemorystream;
begin
SocketStatusBar.Panels[0].Text:='客户端'+Socket.RemoteHost+'正在读信息...';
Showmessage('step1');
RecLength:=Socket.ReceiveLength;
Showmessage('step2');
SetLength(TotalByteArr,RecLength);
Showmessage('step3');
Socket.ReceiveBuf(TotalByteArr,RecLength);
Showmessage('step4');
Memo2.Lines.Add(InttoStr(RecLength));
Showmessage('step5');
m.Write(TotalByteArr,RecLength); <----就是这句话出错了!为什么?好象读不出TotalByteArr。但RecLength却是正确的,为什么?
Showmessage('step6');
m.Position:=0;
Socketbmp := TBitmap.Create;
Socketbmp.LoadFromStream(m);
Socketbmp.SaveToFile('c:/MySocket.jpg');
Showmessage('step6');
Socketbmp.Free;
。。。。
end;