有没有采用ctBlocking方式收数据的ClientSocket的例子,急需,要测试通过的

解决方案 »

  1.   

    看看这篇文章,希望对你有帮助:
    http://www.nssoft.net/delphihelp.asp
      

  2.   

    This example shows the execute method of a thread used to send requests to a server over a socket connection:procedure TMyClientThread.Execute;var
      TheStream: TWinSocketStream;
      buffer: string;
    begin
      { create a TWinSocketStream for reading and writing }
      TheStream := TWinSocketStream.Create(ClientSocket1.Socket, 60000);
      try
        { fetch and process commands until the connection or thread is terminated }
        while (not Terminated) and (ClientSocket1.Active) do
        begin
          try
            GetNextRequest(buffer); { GetNextRequest must be a thread-safe method }        { write the request to the server }
            TheStream.Write(buffer, Length(buffer) + 1);
            { continue the communication (eg read a response from the server) }
            ...
          except
            if not(ExceptObject is EAbort) then
              Synchronize(HandleThreadException); { you must write HandleThreadException }
          end;
        end;
      finally
       TheStream.Free;
      end;
    end;