比如我要向IP为58.25.23.1,端口为 5166 的主机发送数据,该怎么样写?请给上注释

解决方案 »

  1.   

    你说反了吧,一般是这样的, TIdTCPClient 向TidTCPServer发送链接请求,成功后,TidTCPServer可以向 
    TIdTCPClient回写数据。服务器:
    unit Unit1;interfaceuses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, IdBaseComponent, IdComponent, IdTCPServer, ExtCtrls, StdCtrls,
      Buttons, jpeg;
    type
      TForm1 = class(TForm)
        IdTCPServer1: TIdTCPServer;
        Image1: TImage;
        procedure IdTCPServer1Execute(AThread: TIdPeerThread);
      private
        { Private declarations }
      public
        { Public declarations }
      end;var
      Form1: TForm1;implementation{$R *.dfm}procedure TForm1.IdTCPServer1Execute(AThread: TIdPeerThread);
    const
      tempimagefile='c:/test.jpg';
    var
      t:tmemorystream;
    begin
      t:=tmemorystream.Create;
      athread.Connection.ReadStream(t,-1,true);
      t.SaveToFile(tempimagefile);
      self.Image1.Picture.LoadFromFile(tempimagefile);
      t.Free;
    end;end.
      

  2.   

    客户端:unit Unit1;interfaceuses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, jpeg, ExtCtrls, IdBaseComponent, IdComponent, IdTCPConnection,
      IdTCPClient, StdCtrls, Buttons;type
      TForm1 = class(TForm)
        Button1: TButton;
        IdTCPClient1: TIdTCPClient;
        Image1: TImage;
        procedure Button1Click(Sender: TObject);
      private
        { Private declarations }
      public
        { Public declarations }
      end;var
      Form1: TForm1;implementation{$R *.dfm}procedure TForm1.Button1Click(Sender: TObject);
    var
      temp:tmemorystream;
    begin
      temp:=tmemorystream.Create;
      self.Image1.Picture.Graphic.SaveToStream(temp);
      self.IdTCPClient1.Connect();
      self.IdTCPClient1.WriteStream(temp);
      self.IdTCPClient1.Disconnect;
      temp.Free;
    end;end.
      

  3.   

    哦,很谢谢你给我搞了这么多代码;
    要是有两个客服端(客服端1为IP1.客服端2为IP2) TIdTCPClient 都向我的电脑连接,我能否向其中的一个IP发送信息使其连接断开?
      

  4.   

    那需要在客户端判断服务端返回的信息,比如返回01,第一个关闭,02,第二个关闭当然也可以发送ip地址,服务端接收后,与本机ip对比,一样的话,就断开
      

  5.   

    朋友,请问 能否给我个例子?我邮箱 [email protected] 
      

  6.   

    你只要把kampan(1,2楼)的程序中的图片换成字符消息就可以了