如何调试? [英] How to debug this?

查看:64
本文介绍了如何调试?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

出于某些原因,当我进入下面的代码时,它跳出了我在下面标记的第二行

迭代。没有其他事情发生 - 没有

错误。


Dim tcpClient As New System.Net.Sockets.TcpClient

tcpClient.Connect( 127.0.0.1,9005)


正确

Dim networkStream As NetworkStream = tcpClient.GetStream()


''如果是networkStream.CanWrite和networkStream.CanRead那么


''做一个简单的写。

Dim sendBytes As [Byte]() = Encoding.ASCII.GetBytes(有人

那里)

networkStream.Write(sendBytes,0,sendBytes.Length)

''将NetworkStream读入字节缓冲区。

Dim bytes(tcpClient.ReceiveBufferSize)As Byte

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

''将从主机收到的数据输出到控制台。

Dim returndata As String = Encoding.ASCII.GetString(bytes)


步入跳出线。其余的代码如下:


Console.WriteLine((主机返回:" + returndata))


''暂停所以用户可以查看控制台输出

Console.ReadLine()

结束时


tcpClient.Close()


有一个发送数据的应用程序的服务器版本。任何建议

如何追溯这个?


谢谢,

Brett

解决方案

" Brett" < no@spam.net>写在

新闻:eW ************** @ tk2msftngp13.phx.gbl:

出于某种原因,我进入下面的代码,它跳出了我在下面标记的第二次迭代。没有别的事情发生 - 没有错误。

Dim tcpClient As New System.Net.Sockets.TcpClient
tcpClient.Connect(" 127.0.0.1",9005)昏暗的networkStream As NetworkStream = tcpClient.GetStream()

''如果是networkStream.CanWrite和networkStream.CanRead那么

' '做一个简单的写。
Dim sendBytes As [Byte]()= Encoding.ASCII.GetBytes(
任何人
那里)
networkStream.Write(sendBytes, 0,sendBytes.Length)
''将NetworkStream读入字节缓冲区。
Dim bytes(tcpClient.ReceiveBufferSize)As Byte
networkStream.Read(bytes,0,
CInt (tcpClient.ReceiveBufferSize))''将从主机收到的数据输出到控制台。 Dim returndata As
String = Encoding.ASCII.GetString(bytes)

步入跳出上面一行。其余代码如下:

Console.WriteLine((主机返回:" + returndata))暂停,以便用户可以查看控制台输出<

tcpClient.Close()

有一个发送数据的服务器版本的应用程序。关于如何追溯这一点的任何建议?

谢谢,
Brett




Not确定你的意思,'跳出''。这是否意味着抛出

异常?你不能进入''GetString(),但我不认为那是

你的意思。


一个快速的解决方案会是使用DataAvailable:


如果networkStream.DataAvailable()那么

networkStream.Read(...)

结束If


或危险的方式...




循环直到networkStream.DataAvailable()


也可以看看是否有任何问题。 (可能在那里放一个柜台并在几百个循环后退出




但是我想你很快就会读到,如果你等待DataAvailable,

都应该按照代码方式工作。


MP




" MeltingPoint" <无** @ all.com>在消息中写道

news:_s ******************** @ rogers.com ...

" ;布雷特" < no@spam.net>在
新闻中写道:eW ************** @ tk2msftngp13.phx.gbl:

出于某种原因,当我踏入下面的代码,它跳出了我在下面标记的第二次迭代。没有别的事情发生 - 没有错误。

Dim tcpClient As New System.Net.Sockets.TcpClient
tcpClient.Connect(" 127.0.0.1",9005)昏暗的networkStream As NetworkStream = tcpClient.GetStream()

''如果是networkStream.CanWrite和networkStream.CanRead那么

' '做一个简单的写。
Dim sendBytes As [Byte]()= Encoding.ASCII.GetBytes(
任何人
那里)
networkStream.Write(sendBytes, 0,sendBytes.Length)
''将NetworkStream读入字节缓冲区。
Dim bytes(tcpClient.ReceiveBufferSize)As Byte
networkStream.Read(bytes,0,
CInt (tcpClient.ReceiveBufferSize))''将从主机收到的数据输出到控制台。 Dim returndata As
String = Encoding.ASCII.GetString(bytes)

步入跳出上面一行。其余代码如下:

Console.WriteLine((主机返回:" + returndata))暂停,以便用户可以查看控制台输出<

tcpClient.Close()

有一个发送数据的服务器版本的应用程序。关于如何追溯这一点的任何建议?

谢谢,
Brett



不确定你的意思, ''跳出''。这是否意味着抛出了一个
异常?你不能进入''GetString(),但我不认为那是什么意思。

快速解决方案是使用DataAvailable:

如果是networkStream.DataAvailable()那么
networkStream.Read(...)
结束如果

或危险的方式......


循环直到networkStream.DataAvailable()

也看看是否有任何事情发生。 (可能在那里放一个计数器并在几百个循环后退出)

但是我想你很快就会读到,如果你等待DataAvailable,
所有应该工作代码明智。

MP




非常好。


如果是networkStream.DataAvailable()那么

networkStream.Read(...)

结束如果


代码工作正常。我有一个关于字节数组的一般问题。

通过tcp / ip流或文件流发送/接收数据总是使用

字节数组。为什么不能使用常规字符串?什么是特别的

关于字节数组?


谢谢,

Brett


"布雷特" < no@spam.net>写在

新闻:ub ************** @ TK2MSFTNGP14.phx.gbl:


" MeltingPoint" <无** @ all.com>在消息中写道
新闻:_s ******************** @ rogers.com ...

" Brett" < no@spam.net>在
新闻中写道:eW ************** @ tk2msftngp13.phx.gbl:

出于某种原因,当我踏入下面的代码,它跳出了我在下面标记的第二次迭代。没有别的事情发生 - 没有错误。

Dim tcpClient As New System.Net.Sockets.TcpClient
tcpClient.Connect(" 127.0.0.1",9005)

虽然是真的
昏暗的networkStream如NetworkStream =
tcpClient.GetStream()

''如果是networkStream.CanWrite和networkStream.CanRead
那么

''做一个简单的写。
Dim sendBytes As [Byte]()= Encoding.ASCII.GetBytes(
任何人
那里)
networkStream.Write(sendBytes,0,sendBytes.Length)
''将NetworkStream读入字节缓冲区。
Dim bytes(tcpClient.ReceiveBufferSize)As Byte
networkStream.Read(bytes ,0,
CInt(tcpClient.ReceiveBufferSize))''将从主机收到的数据输出到控制台。 Dim returndata As
String = Encoding.ASCII.GetString(bytes)

步入跳出上面一行。其余代码如下:

Console.WriteLine((主机返回:" + returndata))暂停,以便用户可以查看控制台输出<

tcpClient.Close()

有一个发送数据的服务器版本的应用程序。关于如何追溯这一点的任何建议?

谢谢,
Brett



不确定你的意思, ''跳出''。这是否意味着抛出了一个
异常?你不能进入''GetString(),但我不认为那是什么意思。

快速解决方案是使用DataAvailable:

如果是networkStream.DataAvailable()那么
networkStream.Read(...)
结束如果

或危险的方式......


循环直到networkStream.DataAvailable()

也看看是否有任何事情发生。 (也许在那里放一个柜台,然后在几百个循环后退出:)

但是我觉得你很快就会读到,如果你等待
DataAvailable,都应该工作代码明智。

MP



非常好。

如果networkStream.DataAvailable()那么
networkStream.Read(...)
结束如果

代码工作正常。我有一个关于字节
数组的一般问题。通过tcp / ip流或文件流发送/接收数据
始终使用字节数组。为什么不能使用常规字符串?什么
字节数组是如此特别?

谢谢,
Brett




我会说它主要与unicode有关。一个字节的字符

只是在全球范围内不做。通过让你使用

Encoding.ASCII / UTF8 / UTF7 / Unicode.GetString / GetBytes微软提醒你b $ b你的目标/省略市场。


有点模糊:
http://msdn.microsoft.com/library/de...classtopic.asp


MP


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

解决方案

"Brett" <no@spam.net> wrote in
news:eW**************@tk2msftngp13.phx.gbl:

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



"MeltingPoint" <no**@all.com> wrote in message
news:_s********************@rogers.com...

"Brett" <no@spam.net> wrote in
news:eW**************@tk2msftngp13.phx.gbl:

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


"Brett" <no@spam.net> wrote in
news:ub**************@TK2MSFTNGP14.phx.gbl:


"MeltingPoint" <no**@all.com> wrote in message
news:_s********************@rogers.com...

"Brett" <no@spam.net> wrote in
news:eW**************@tk2msftngp13.phx.gbl:

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/de...classtopic.asp

MP


这篇关于如何调试?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆