TServerSocket的阻塞模式时读取数据,如果CLIENT一直发送,而SERVER没处理完,
就会报错。这个问题怎么处理?

解决方案 »

  1.   

    server没处理完,CLIENT应该无法成功发送的,在CLIENT 的SENDBUF返回值就可以看出。
      

  2.   

    如果CLIENT端的计算机突然断电,断网线 Server如何快还知道????不要设什么Time Out
    浪费资源!万分对不起jjweb (jjweb) ,不好意思!!!!!!!!!
      

  3.   

    to halfdream(哈欠)
    我不是用SENDBUF,我是用SENGSTREAM,在那里可以知道返回值?
    另外:我这里出现的现象是,CLIENT一直发送,如果SERVER没处理过来,就会报错。
      

  4.   

    SENDSTREAM实际是这样的:SendStream调用了 SendStreamPiece...
    function TCustomWinSocket.SendStreamPiece: Boolean;
    var
      Buffer: array[0..4095] of Byte;
      StartPos: Integer;
      AmountInBuf: Integer;
      AmountSent: Integer;
      ErrorCode: Integer;
    ....
    begin
      Lock;
    ......
          while True do
          begin
            StartPos := FSendStream.Position;
               //从流中读一块数据到BUF。
            AmountInBuf := FSendStream.Read(Buffer, SizeOf(Buffer));        if AmountInBuf > 0 then //有数据要发
            begin
              AmountSent := send(FSocket, Buffer, AmountInBuf, 0);//发送
              if AmountSent = SOCKET_ERROR then//确定知道发送失败
              begin
                ErrorCode := WSAGetLastError;//抛出异常
                。。
                  Break;
                end;
              end else if AmountInBuf > AmountSent then//已经发出数量少于想发数量。
                FSendStream.Position := StartPos + AmountSent
              else if FSendStream.Position = FSendStream.Size then//到流终点。。
              begin
                DropStream;
                Break;
              end;
            end else
            begin
              DropStream;
              Break;
            end;
          end;
          Result := True;
    ....
    end;SendStream也不过这样回事,发不出去就死缠着再发,除非确定失败或发完。。
    所以我不喜欢用它,呵呵。你可以想想它的流程,或者跟踪调试进去,应该很容易明白错误原因。