以下只是发送文件的代码,我想加一段程序,再发送完文件后再把文件名、客户端ID等数据也发过去,该怎样修改,十分感谢!
//这是服务器端
procedure TForm1.ServerSocket1ClientRead(Sender: TObject;
Socket: TCustomWinSocket);
var
MyBuffer: array[0..1000] of byte; {设置接收缓冲区}
MyReceviceLength: integer;
MyBmp: TBitmap;
begin
MyReceviceLength := socket.ReceiveLength; {读出包长度}
Socket.ReceiveBuf(MyBuffer, MyReceviceLength); {接收数据包并读入缓冲区内}
MyStream.Write(MyBuffer, MyReceviceLength); {将数据写入流中}
MyStream.Position := 0;
MyBmp := tbitmap.Create;
try
Mybmp.LoadFromStream(MyStream); {将流中的数据读至图像对象中}
Mybmp.SaveToFile(GetCurrentDir+'/'+R_ip+'.bmp');
Image1.Picture.Bitmap.Assign(MyBmp); {分配给image1元件 }
finally {以下为清除工作 }
MyBmp.free;
MyStream.Clear;
end;
end;
//这是客户端
procedure TForm1.Button2Click(Sender: TObject);
var
MyBmp: TBitmap;
begin
try
MyStream := TMemorystream.Create;{建立内存流}
MyBmp := TBitmap.Create;
MyBmp.LoadFromFile(edit2.text); {True表示抓鼠标图像}
Mybmp.SaveToStream(MyStream); {将JPG图象写入流中}
MyStream.Position := 0;{注意:必须添加此句}
finally
MyBmp.free;
end;
ClientSocket1.Socket.SendStream(MyStream); {将流发送出去}
// MyStream.Clear;
end;