嘿所有我有以下代码,我通过网络向Onkyo A / V接收器发送命令。我也希望从中获得反馈,但我似乎无法找到这样做的方法。我知道要发送的命令让它发回一些东西但是对于下面的代码,它只发出一个命令并且不会监听返回。这就是我需要帮助的地方:
Private Sub SendCommand(ByVal command As String)
Dim Stream As NetworkStream
Dim Client As New TcpClient()
Dim streamw As StreamWriter
Dim i As Int32
Client.Connect("192.168.9.100", 60128)
Stream = Client.GetStream()
If Client.Connected And Stream.CanWrite Then
streamw = New StreamWriter(Stream)
Dim sendBytes(command.Length + 18) As Char
sendBytes(0) = "I"
sendBytes(1) = "S"
sendBytes(2) = "C"
sendBytes(3) = "P"
sendBytes(4) = Chr(0)
sendBytes(5) = Chr(0)
sendBytes(6) = Chr(0)
sendBytes(7) = Chr(16)
sendBytes(8) = Chr(0)
sendBytes(9) = Chr(0)
sendBytes(10) = Chr(0)
sendBytes(11) = Chr(command.Length + 3)
sendBytes(12) = Chr(1)
sendBytes(13) = Chr(0)
sendBytes(14) = Chr(0)
sendBytes(15) = Chr(0)
sendBytes(16) = "!"
sendBytes(17) = "1"
For i = 0 To (command.Length - 1)
sendBytes(18 + i) = command.Chars(i)
Next
sendBytes(command.Length + 18) = Chr(13) '&HD
streamw.Write(sendBytes)
'Dim bytes(Client.ReceiveBufferSize) As Byte
'Stream.Read(bytes, 0, CInt(Client.ReceiveBufferSize))
'Dim returndata As String = Encoding.ASCII.GetString(bytes)
'Debug.Print(("Host returned: " + returndata))
streamw.Flush()
Else
MsgBox("error: Stream writing failed")
End If
Client.Close()
End Sub
任何帮助都会很棒!感谢
大卫