Q&A

  • ClientSocke사용. - 데이타를 받을때 다 못 처리해줘요..도와주세요
안녕하세요..다름이 아니라 소켓통신을 하여 데이타를 받아서 처리를 해주려고하는데

남은데이타가 있음에도 불구하고 데이타를 뿌려주지 못합니다.

아래는 소켓 Read 되는 부분만 발췌한것입니다... 다른 부분도 필요하면

같이 올려드리겠습니다.

제 생각에 문제는 아래와 같은 부분에서 문제가 되지 않나 싶습니다.

이부분에 멀 더 첨부를 해야하는건지..ㅡㅡ

고수님 도와주십시요..

        else if (size  > 2) then
        begin
            parse(buf);

//            while (Socket.ReceiveLength > 0) do
//            begin
//                parse(buf);                                    --> 여기 주석은 제가
//            end;                                                       넣어봤는데...그냥
                                                                           한없이 돌더군요.ㅡㅡ
            hasSize := False;
        end;

======================================================================

procedure TForm1.cSocketRead(Sender: TObject; Socket: TCustomWinSocket);
var
  size, Length, i : Integer;
  buf : Array[0..1024] of Byte;
  command : Byte;
  Station_Context : Array of Station_Context_t;
begin
    size := Socket.ReceiveLength;
    Socket.ReceiveBuf(buf, size);

    if (size = 0) then
        Exit;

    Memo1.Lines.Add('Size = ' + IntToStr(Size));

    readPos := 0;
    if (isFirstPacket = True) then
    begin
        command := getLEByte(buf, readPos);
        isFirstPacket := False;
        if (command = 65) then
        begin
            Length := getLEWord(buf, readPos);
            setLength(Station_Context, Length);

            Memo1.Lines.Add(IntToSTr(command));
            Memo1.Lines.Add(IntToStr(Length));
            Memo1.Lines.Add('==========================');

            for i := 0 to Length -1 do
            begin
                Station_Context[i].startTime      := getLEInt64(buf, readPos);
                Station_Context[i].stationID      := getLEWord(buf, readPos);
                Station_Context[i].countBroker    := getLEInt(buf, readPos);
                Station_Context[i].channelIP      := getAddress(buf, readPos);
                Station_Context[i].channelPort    := getLEInt(buf, readPos);
                Station_Context[i].subStreamCount := getLEInt(buf, readPos);

                RequestBrokerList(Station_Context[i].stationID);
            end;

            Station_List(Station_context);
            Station_context := nil;
        end;
    end
    else
    begin
        if (size = 2) then
        begin
            hasSize := True;
        end
        else if (size  > 2) then
        begin
            parse(buf);                             -->이 부분에서 첨가가 되야 하는지
            hasSize := False;                        구문이틀린건지..ㅡㅡ 도와주세요
        end;
    end;
end;

procedure TForm1.Parse(buf: Array of byte);
var
  command : Byte;
  Length, i : Integer;
  Station_Context : Station_Context_t;
  Broker_Context : Broker_Context_t;
begin
    if (hasSize = False) then
    begin
        Length := getLEWord(buf, readPos);
        Memo1.Lines.Add('Length = ' + IntToStr(Length));
    end;

    command := getLEByte(buf, readPos);
    Memo1.Lines.Add(IntToStr(command));

    case (command) of

//      STATION_CREATED
        63 :
        begin
            Station_Context.startTime      := getLEInt64(buf, readPos);
            Station_Context.stationID      := getLEWord(buf, readPos);
            Station_Context.countBroker    := getLEInt(buf, readPos);
            Station_Context.channelIP      := getAddress(buf, readPos);
            Station_Context.channelPort    := getLEInt(buf, readPos);
            Station_Context.subStreamCount := getLEInt(buf, readPos);

            Station_Created(Station_Context);
        end;

//        STATION_CLOSED
        64 :
        begin
            Station_Context.stationID := getLEWord(buf, readPos);

            Station_Closed(Station_Context.stationID);
        end;

//      BROKER_CONNECTED
        66 :
        begin
            Broker_Context.startTime     := getLEInt64(buf, readPos);
            Broker_Context.brokerId      := getLEWord(buf, readPos);
            Broker_Context.externalIp    := getAddress(buf, readPos);
            Broker_Context.internalIP    := getAddress(buf, readPos);
            Broker_Context.StationID     := getLEWord(buf, readPos);
            Broker_Context.osName_Length := getLEWord(buf, readPos);
            Broker_Context.osName        := getString(buf, readPos, Broker_Context.osName_Length);

            Broker_Connected(Broker_Context);
        end;
    end;
end;
0  COMMENTS