J
jineric
Unregistered / Unconfirmed
GUEST, unregistred user!
吾想传输一BMP文件到另一台机器显示,我是这样做的:
传输端:
var stream: TMemoryStream;
stream.LoadFromFile('c:/xxx.bmp');
ServerSocket1.Socket.Connections[0].SendStream(stream);
ServerSocket1.Socket.Connections[0].SendText('ok');
接受端:
var stream: TMemoryStream;
procedure TForm1.ClientSocket1Read(Sender: TObject;
Socket: TCustomWinSocket);
var
b: array [1..10000] of Byte;
len: integer;
begin
len:= Socket.ReceiveLength;
if len <> 2 then
begin
Socket.ReceiveBuf(stream,len); //因为socket不能一次把数据传
stream.Write(b,len); //到接受端,所以得拼接。
end
else
begin
stream.Position:=0; //如果收到'ok'就显示,并
//把position的位置置0.
image1.Picture.Bitmap.LoadFromStream(stream);
end;
end;
可我在接受端就是得不到图象,也不知道错在哪里?
望各位一定要鼎力帮助我哦!!!
传输端:
var stream: TMemoryStream;
stream.LoadFromFile('c:/xxx.bmp');
ServerSocket1.Socket.Connections[0].SendStream(stream);
ServerSocket1.Socket.Connections[0].SendText('ok');
接受端:
var stream: TMemoryStream;
procedure TForm1.ClientSocket1Read(Sender: TObject;
Socket: TCustomWinSocket);
var
b: array [1..10000] of Byte;
len: integer;
begin
len:= Socket.ReceiveLength;
if len <> 2 then
begin
Socket.ReceiveBuf(stream,len); //因为socket不能一次把数据传
stream.Write(b,len); //到接受端,所以得拼接。
end
else
begin
stream.Position:=0; //如果收到'ok'就显示,并
//把position的位置置0.
image1.Picture.Bitmap.LoadFromStream(stream);
end;
end;
可我在接受端就是得不到图象,也不知道错在哪里?
望各位一定要鼎力帮助我哦!!!