用了Indy以后我不担心多线程的问题。我的客户端和服务器端需要多次传送不同性质的数据,所以服务器端是否要使用循环代码读取客户端的内容?客户端通过发送不同的前缀让服务器知道并接收其后的数据。请高手解答。

解决方案 »

  1.   

    procedure TMainFrm.IdTCPServerExecute(AThread: TIdPeerThread);
    var
      MyRec : ClientWareRecord;
      SourceBmp : TBitmap;
      fbuf1:TMemoryStream;
      LibHandle: THandle;
      Jpg:Tjpegimage;
      protsTmp,strmypath,strMyip:string;
      ShowCalendar:Procedure(SourceBmp: TBitmap; Width, Height: Integer; JpgPath :string);
      Com,     // System command
      Msg,sTmp    : String;
    begin
        AThread.connection.ReadBuffer(MyRec,SizeOf(MyRec));
        if MyRec.ClientComType = MP_GETTBMPTOTJPG then
        begin          try 
                SourceBmp := TBitmap.Create;
                SourceBmp.PixelFormat := pf24bit;
                SourceBmp.LoadFromFile(MyRec.ServerPath);
                jpg := TJPEGImage.Create;
                jpg.Assign(SourceBmp);
                //jpg.SaveToFile(JpgPath);
                //===================================================================
                fbuf1:=TMemoryStream.Create;
                //===================================================================
                jpg.SaveToStream(fbuf1);
                SourceBmp.FreeImage;
                FreeAndNil(SourceBmp);
                FreeAndNil(jpg);
                AThread.Connection.OpenWriteBuffer;
                AThread.Connection.Writestream(fbuf1,true,false);
              finally
                AThread.Connection.CloseWriteBuffer;
              end; 
      end;
    end;