Re: How to debug this?



"Brett" <no@xxxxxxxx> wrote in
news:ubaN0QaNFHA.3844@xxxxxxxxxxxxxxxxxxxx:

>
> "MeltingPoint" <none@xxxxxxx> wrote in message
> news:_s6dnStYC5jC9tbfRVn-jg@xxxxxxxxxxxxx
>> "Brett" <no@xxxxxxxx> wrote in
>> news:eWx8RjZNFHA.1096@xxxxxxxxxxxxxxxxxxxx:
>>
>>> For some reason when I step into the code below, it jumps out on the
>>> second iteration at the line I have marked below. Nothing else
>>> happens - no errors.
>>>
>>> Dim tcpClient As New System.Net.Sockets.TcpClient
>>> tcpClient.Connect("127.0.0.1", 9005)
>>>
>>> While True
>>> Dim networkStream As NetworkStream =
>>> tcpClient.GetStream()
>>>
>>> 'If networkStream.CanWrite And networkStream.CanRead
>>> Then
>>>
>>> ' Do a simple write.
>>> Dim sendBytes As [Byte]() = Encoding.ASCII.GetBytes("Is
>>> anybody
>>> there")
>>> networkStream.Write(sendBytes, 0, sendBytes.Length)
>>> ' Read the NetworkStream into a byte buffer.
>>> Dim bytes(tcpClient.ReceiveBufferSize) As Byte
>>> networkStream.Read(bytes, 0,
>>> CInt(tcpClient.ReceiveBufferSize)) ' Output the data
>>> received from the host to the console. Dim returndata As
>>> String = Encoding.ASCII.GetString(bytes)
>>>
>>>
>>>
>>> Step into jumps out at above line. The rest of the code follows:
>>>
>>> Console.WriteLine(("Host returned: " + returndata))
>>>
>>> ' pause so user can view the console output
>>> Console.ReadLine()
>>> End While
>>>
>>> tcpClient.Close()
>>>
>>> There is a server version of the app that is sending data. Any
>>> suggestions on how I can trace this down?
>>>
>>> Thanks,
>>> Brett
>>>
>>>
>>>
>>
>> Not sure what you mean, 'jumps out'. Does that mean it throws an
>> exception? You can't 'step into' GetString() but I don't think thats
>> what you mean.
>>
>> A quick solution would be to use DataAvailable:
>>
>> If networkStream.DataAvailable() Then
>> networkStream.Read(...)
>> End If
>>
>> OR the dangerous way...
>>
>> Do
>> Loop Until networkStream.DataAvailable()
>>
>> too see if anything ever comes. (maybe put a counter in there and
>> exit after a couple hundred loops :)
>>
>> but i think your trying to read to soon, if you wait on
>> DataAvailable, all should work code wise.
>>
>> MP
>
> Very nice. The
>
> If networkStream.DataAvailable() Then
> networkStream.Read(...)
> End If
>
> code is working fine. I have a general question about the byte
> array. Sending/receiving data via the tcp/ip streams or file streams
> always uses the byte array. Why can't a regular string be used? What
> is so special about the byte array?
>
> Thanks,
> Brett
>
>
>

I would say it mostly has to do with unicode. One byte characters
just don't do it on the global scale. By making you use
Encoding.ASCII/UTF8/UTF7/Unicode.GetString/GetBytes Microsoft is reminding
you of which market your targeting/omitting.

A little blurp:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemtextencodingclasstopic.asp

MP
.



Relevant Pages

  • Re: How to debug this?
    ... >> Step into jumps out at above line. ... > Loop Until networkStream.DataAvailable ... I have a general question about the byte array. ... Sending/receiving data via the tcp/ip streams or file streams always uses ...
    (microsoft.public.dotnet.languages.vb)
  • Re: Wheres my pin fear abatement coaching fee Jerry/ now pay in push ups boy
    ... should have been checked twice by then anyway! ... which can shift a pin from its loop greatly drop off from where they ... Wearing booties, 800 Jumps? ... the guy always checked his pin before ...
    (rec.skydiving)
  • Re: 2 questions about my array/range...
    ... the game player jumps, based on the farthest passible tile. ... the method, I used a 'for i' statement with 0 to the max distance, for ... So basically, instead of returning an array, it returns a Range. ... Intro to Ruby on Rails July 21-24 Edison, ...
    (comp.lang.ruby)
  • Re: Help regarding fortran code
    ... It does not conform to the standard. ... It is not allowed to goto the CONTINUE line from outside of the DO ... DO loop to inside of it. ... applying only to jumps from outside of the loop. ...
    (comp.lang.fortran)
  • Re: Next w/o For If/Then Loop
    ... A few short jumps don't hurt no one no how. ... > outside of Error Handling, because it leads to sloppy practices and ... My For/Next Loop scans a list of Dates and then transfers ...
    (microsoft.public.excel.misc)

Loading