我对其中的BUF有些不理解,他到底是什么东西!

解决方案 »

  1.   

    sendbuf你可以将数据封装在一个数据包里面
    比如说你要传一个学生的信息
    type
    strudent =record
      name : string[20];
      age: integer;
      number: string[10];
    end;
    这样不需要将name,age,number等一个一个的发送出去
    而是可以将一个数据包直接发送出去
      

  2.   


    type
        PUdpPak = ^UdpPak;
        UdpPak=record
        Time: TDateTime;
        ErrClient: String[20];
        AppName: String[50];
        Msg: String[255];
        Url: String[255];
        Popup: Boolean;
    end;function TAlertServer.AlarmInLan(Time: TDateTime;App,ErrClient,Msg,Url: String;Popup: Boolean=False): integer;
    var
        Upack: PUdpPak;
    begin
        New(Upack);
        Upack^.Time := Now;
        Upack^.AppName := App;
        Upack^.ErrClient := ErrClient;
        Upack^.Msg := Msg;
        Upack^.Url := Url;
        Upack^.Popup := Popup;    try
            IdUDPClient1.Host := '192.168.0.255';
            IdUDPClient1.SendBuffer(Upack^,sizeof(UdpPak));
        finally
            Dispose(Upack);
        end;    Result := 1;end;
    这是从我自己地程序里面截下来的,参考参考吧
      

  3.   

    我记得以前做个一次,好像那时用的是强行转换之类的,你可以try.try。
      

  4.   

    调用Socket.SendBuf()我发现不是马上发出去的,好像有个什么缓冲池之类,我学东西半桶水,有高手能出来说说道理吗?有的话我另开贴。
      

  5.   

    帮助里面写的这么清楚,难道你们就不看帮助吗?
    TCustomWinSocket.SendBufWrites Count bytes to the socket connection from the Buf parameter.function SendBuf(var Buf; Count: Integer): Integer;DescriptionUse SendBuf to write to the socket connection. Call this method from the OnSocketEvent event handler of a Windows socket object or in the OnWrite or OnClientWrite event handler of a socket component. Alternately, Use SendBuf to write when a connection is first formed when the socket does not expect notification that the socket on the other end of the connection is expecting to read.For non-blocking sockets, the data is sent to the WinSock DLL which has it's own internal buffers. If the WinSock can accept additional data, SendBuf returns immediately with the number of bytes queued. If the WinSock internal buffer space is not able to accept the buffer being sent, SendBuf returns -1 and no data is queued at all. In this case, wait a bit for the WinSock to have a chance to send out already-queued data; then try again.For blocking sockets, SendBuf returns the number of bytes actually written. If an error occurs while writing to the connection, SendBuf terminates the connection and raises an ESocketError exception.
      

  6.   

    TCustomWinSocket.ReceiveBufReads up to Count bytes from the socket connection into the Buf parameter.function ReceiveBuf(var Buf; Count: Integer): Integer;DescriptionUse ReceiveBuf to read from the socket connection in the OnSocketEvent event handler of a Windows socket object or in the OnRead or OnClientRead event handler of a socket component. ReceiveBuf returns the number of bytes actually read. If no bytes are read, ReceiveBuf returns ?.ReceiveBuf only works in response to a read notification to a non-blocking windows socket. Blocking sockets must use a TWinSocketStream for reading. The TWinSocketStream object waits for the remote socket to be ready before transferring information.Note: While the ReceiveLength method can return an estimate of the size of buffer required to retrieve information from the socket, the number of bytes it returns is not necessarily accurate.
      

  7.   

    ReceiveBuf的好处是你可以从接收Buf中读取指定长度的内容,而不是像ReceiveText一样读取所有的内容,这样可以根据自己的协议安需要从Socket上读取数据了,不必在乎对方是一次发的,还是多次发的数据。因为有可能,对方几次SendText,而这端只是触发了一次OnRead事件。