Thank you so much Wilfred for your quick answer.

One question:

I do that

    int length = FWSocket->RcvdCount;

    if(length == 0)
        return;

    char *str = new char[length + 1];

    FWSocket->Receive(str, length);

    str[length] = 0;

you wrote that sometimes FWSocket->RcvdCount is 0. 

What should I do to receive data?

I prefer to read char array because I have chars with value < 0x20

Thank you
Regards
Ing. Alessandro Miorelli

Software Engineer
Microgate S.r.l.
Via Stradivari 4
39100 Bolzano (BZ) Italy
www.microgate.it
Tel. +390471501532

-----Original Message-----
From: TWSocket [mailto:twsocket-boun...@lists.elists.org] On Behalf Of
Wilfried Mestdagh
Sent: Tuesday, January 9, 2018 6:07 PM
To: twsoc...@elists.org
Subject: Re: [twsocket] ICS OnDataAvailable

I see a second problem in your code:

  } while (length != totalDataReceived && FWSocket->State == wsConnected &&
!Terminated && timeout < MAX_TIMEOUT);

Dont loop in DataAvailable. Just receive the part of data that is received
and exit. When next chunck of data come in the OnDataAvailable will be fired
again. TCP protocol does not respect data boundaries.

Met vriendelijke groeten,
Wilfried Mestdagh

Op 09-01-18 om 18:01 schreef Wilfried Mestdagh:
> Hi,
>
> The problem could be in this peace of code:
>
> int length = FWSocket->RcvdCount;
>
>     if(length == 0)
>     {
>         Debug::DebugString(AnsiString("FWSocketDataAvailable length ")
> + IntToStr(length));
>         return;
>     }
>
> RcvdCount is not reliable. This is not a TWSocket problem but a 
> Windows problem. Even if it returns zero the you should try to receive 
> data. So just leave that part out of it.
>
> Rgds, Wilfried
>
> Met vriendelijke groeten,
> Wilfried Mestdagh
>
> Op 09-01-18 om 15:48 schreef Alessandro Miorelli:
>> Hi,
>>
>> I'm working with ICS and BCB6
>>
>> All works fine but sometimes I don't receive OnDataAvailable event 
>> anymore.
>>
>> In attach the code.
>>
>> Please could you help me
>>
>>
>> Regards
>>
>>
>> Ing. Alessandro Miorelli
>>
>>
>> Software Engineer
>>
>>
>>
>>
>

--
To unsubscribe or change your settings for TWSocket mailing list please goto
http://lists.elists.org/cgi-bin/mailman/listinfo/twsocket
Visit our website at http://www.overbyte.be

-- 
To unsubscribe or change your settings for TWSocket mailing list
please goto http://lists.elists.org/cgi-bin/mailman/listinfo/twsocket
Visit our website at http://www.overbyte.be

Reply via email to