Re: How is this conditional able to execute?



This is getting scary :)

Lets take this one step at a time.

I'm a bit perplexed as to why a recieve buffer would be such a strange size.
Could it be that the value of tcpClient.ReceiveBufferSize is actually 8192
(8KB)? If so, then the array declaration should be:

Dim bytes(tcpClient.ReceiveBufferSize - 1) As Byte

In VB.NET, arrays are 0 based and the value specified is the upper bound of
the array as opposed to the number of elements (as in C#.NET).

Can you dump the first 50 bytes of the array on the first call. Directly
after the line:

networkStream.Read(bytes, 0, tcpClient.ReceiveBufferSize)

insert:

For _i As Integer = 0 to 48
Console.Write("{0},", bytes(_i).ToString())
Next
Console.WriteLine("{0}", bytes(_i).ToString())

Add another line:

Console.WriteLine()

and place a breakpoint on this line.

Run the code then copy and paste the result into a post to this thread.

It will be interesting to see just what characters are arriving.

A new byte array is created each time the networkStream object is read so
there is nothing from the previous red remaining. Therefore the comment
about the 'values shifting' is a red herring. What you are getting is
actually what is coming from the networkStream object.

Also, is there any particular reason why you are using UTF8 encoding to
interpret the data? Is it specified somewhere that the data arriving in the
networkStream object is actually UTF8 or is just a stab in the dark?


"Brett" <no@xxxxxxxx> wrote in message
news:%23aS0EDARFHA.2744@xxxxxxxxxxxxxxxxxxxxxxx
>I tried this but it isn't working either. At one point, the bytes array
>has non zero elements up to element 35. returndata has the value of "" (or
>so it seems) and length of 8193, same as the bytes array. Through each
>pass of the loop, the non zero elements increase in the bytes array. So
>it goes from element 35 to 36, 37 and so on. The values are shifting so
>that the first 10 are now zero. Then the first 11, 12, 13 and so on.
>
> Any other suggestions?
>
> Thanks,
> Brett
>
> "Stephany Young" <noone@localhost> wrote in message
> news:u1TlDb9QFHA.2680@xxxxxxxxxxxxxxxxxxxxxxx
>> Sorry, my mistake. Null (Chr(0)) is not treated as whitespace by the
>> String.Trim Method.
>>
>> Instead, you can can use one of the overloaded String.Trim methods.
>>
>> Dim returndata As String =
>> Encoding.UTF8.GetString(bytes).Trim(Char.MinValue)
>>
>> Char.MinValue is a constant for 0x00 which equates to Null or Chr(0).
>>
>> This overload removes all occurrences of a set of characters specified in
>> an array from the beginning and end of the string instance.
>>
>>
>> "Brett" <no@xxxxxxxx> wrote in message
>> news:uPLcAZ6QFHA.3988@xxxxxxxxxxxxxxxxxxxxxxx
>>>
>>> "Stephany Young" <noone@localhost> wrote in message
>>> news:%23hNf834QFHA.3988@xxxxxxxxxxxxxxxxxxxxxxx
>>>> What test are you using to determine that returndata.ToString = ""?
>>>>
>>>> Are you , for example, executing a:
>>>>
>>>> Console.Writeline("returndata.ToString = " & returndata.ToString)
>>>>
>>>> and getting the result:
>>>>
>>>> returndata.ToString =
>>>>
>>>> Your comment about returndata 'always' being 8193 bytes gives us the
>>>> clue as what is happening.
>>>>
>>>> I suspect that returndata is padded with null characters (chr(0)).
>>>>
>>>> The Trim function (aka Microsoft.VisualBasic.Trim) only 'trims' leading
>>>> and trailing Space characters.
>>>>
>>>> The String.Trim Method 'trims' leading and trailing whitespace
>>>> characters. 'whitespace' comprises a number of characters including the
>>>> null character (chr(0)).
>>>>
>>>> I think that if you change the line:
>>>>
>>>> Dim returndata As String = Trim(Encoding.UTF8.GetString(bytes))
>>>>
>>>> to
>>>>
>>>> Dim returndata As String = Encoding.UTF8.GetString(bytes).Trim()
>>>>
>>>> then the test will work correctly.
>>>
>>> That doesn't work either. In some cases, bytes will come in as a zero
>>> byte array with length 8193. Every element in that array will be zero.
>>> returndata is assigned and its length becomes 8193 as well.
>>>
>>>
>>
>>
>
>


.



Relevant Pages

  • Re: Arrays of zero length
    ... The minor strangeness is that when you allocate an array to zero size, ... saying something like that allocating an array makes it undefined ... In f77, zero-size was disallowed, ...
    (comp.lang.fortran)
  • Re: should every thing be zero indexed?
    ... Other families of languages count from 1. ... its number is zero: I always start counting at zero". ... > as a fundamental concept in both the definition of array indices and ... > for I in foo'range loop ...
    (comp.programming)
  • Re: Subset Sum problem (w/ limited scope)
    ... The "Subset Sum" problem (stated various ways depending on what you ... a subset of those integers that sums up to zero. ... Are there going to be duplicate values in your original array? ...
    (comp.lang.fortran)
  • Re: addEvent - The late entry :)
    ... take any number of arguments and append them to an array. ... argument, which is fine on everything but Firefox, where it makes the ... 20 arguments Windows Safari 3 executes that expression in 48% of the ... and at zero arguments 47%. ...
    (comp.lang.javascript)
  • Re: Subset Sum problem (w/ limited scope)
    ... The "Subset Sum" problem (stated various ways depending on what you ... a subset of those integers that sums up to zero. ... Are there going to be duplicate values in your original array? ...
    (comp.lang.fortran)