Может кто-нибудь сказать мне, почему мой код зависает в "Return sockReader.ReadLine ()"?Спасибо.Я пытаюсь получить информацию с моего сервера Raspberry Pi, когда отправляю команду с помощью «Public Sub Send», и код застревает.
Imports System.Net
Imports System.Net.Sockets
Imports System.IO
Public Class TCPControl
Public sock As TcpClient
Public DataStream As StreamWriter
Public DataGet As TcpListener
Private netStream As NetworkStream
Private sockReader As StreamReader
Public Sub New(Host As String, Port As Integer)
' CLIENT
sock = New TcpClient(Host, Port)
netStream = sock.GetStream()
sockReader = New StreamReader(netStream)
DataStream = New StreamWriter(sock.GetStream)
Dim localAddr As IPAddress = IPAddress.Parse("172.16.2.104")
DataGet = New TcpListener(localAddr, 6969)
End Sub
Public Sub Send(Data As String)
DataStream.Write(Data & vbCrLf)
DataStream.Flush()
End Sub
Public Function Receive()
Dim howMany As Integer = sock.Available()
If netStream.DataAvailable Then
Return sockReader.ReadLine()
End If
Return howMany
End Function
End Class