0
由於NetworkStream.Length
從未實現過,我怎麼才能看到網絡流上已有多少數據。.Net NetworkStream.Length未實現如何知道流中有多少數據
注意,我不能只是簡單地Read()
而DataAvailable=True
我使用一個線程,保存着,而DataAvailable
設置運行的功能,那麼這個功能應該削減的那批掉。
這是我的破碎的功能只是爲了顯示我想要實現的。
我的所有分組都與[2 Bytes Size][1 Byte Type][Optional Payload]
Public Function readPacket() As PacketReader
'This cuts the stream of bytes into readable packets.
Try
If serverStream.DataAvailable Then
If packetSize = 0 Then
packetSize = serverReader.ReadUInt16()
packetType = serverReader.ReadByte()
End If
If packetSize = 0 Then
Return New PacketReader(packetType, New MemoryStream())
End If
If serverStream.Length >= packetSize Then
Dim packet() As Byte = serverReader.ReadBytes(packetSize)
Dim stream As Stream = New MemoryStream(packet)
Dim tmpPacketSize As UShort = packetSize
packetSize = 0
Return New PacketReader(packetType, tmpPacketSize, stream)
End If
End If
Catch e As Exception
formLobby.logMsg("Exception: " + e.ToString)
End Try
Return Nothing
End Function