这似乎是最明显的事情,但我只是不知道如何使用 TCPClient 和 TCPListener 获取通过网络发送的字节长度?到目前为止,这是我的代码:
'Must listen on correct port- must be same as port client wants to connect on.
Const portNumber As Integer = 9999
Dim tcpListener As New TcpListener(IPAddress.Parse("192.168.2.7"), portNumber)
tcpListener.Start()
Console.WriteLine("Waiting for connection...")
'Accept the pending client connection and return
'a TcpClient initialized for communication.
Dim tcpClient As TcpClient = tcpListener.AcceptTcpClient()
Console.WriteLine("Connection accepted.")
' Get the stream
Dim networkStream As NetworkStream = tcpClient.GetStream()
'' Read the stream into a byte array
我需要获取网络流的长度来设置要读取数据的字节数组的大小。但是 networkStream.length 不受支持并且不起作用并引发 Notsupportedexception。
我能想到的唯一另一种方法是在发送数据之前发送数据的大小,但这似乎很长。