zoukankan      html  css  js  c++  java
  • INDY流的发送和接收

    发送

    try
        s := 'Hello world!';
        stream := TStringStream.Create(s);
        IdTCPClient1.OpenWriteBuffer;
        IdTCPClient1.WriteInteger(stream.Size);//注意这里:要先写入流的长度,在读取的时候如果使用      AThread.Connection.ReadStream(stream);
        IdTCPClient1.WriteStream(stream, true);
      finally
        IdTCPClient1.CloseWriteBuffer;
        stream.Free;
      end;

    接收

    procedure TServerForm.IdTCPServer1Execute(AThread: TIdPeerThread);
    var stream: Tstream;
    begin

      if not AThread.Terminated and AThread.Connection.Connected then
      begin
        stream := TStringStream.Create('');

        AThread.Connection.ReadStream(stream);//这句相当于ReadStream(stream,-1,false),就是根据流的前四个字节读出流长度,然后再将流读出
        stream.Position := 0;
        Memo1.Lines.LoadFromStream(stream);

      end;

  • 相关阅读:
    java方法名的重载
    数据库ifnull方法
    java类的方法
    java属性的默认值
    sublime使用攻略
    1046 Shortest Distance
    1047 Student List for Course
    1048 Find Coins
    1049 Counting Ones
    1050 String Subtraction
  • 原文地址:https://www.cnblogs.com/hnxxcxg/p/2940677.html
Copyright © 2011-2022 走看看