Hello,
I’ve been messing with a program to log into a router and pull some information over the API. I’ve been using the VB.net example listed on the wiki here: http://wiki.mikrotik.com/wiki/API_in_VB_dot_NET
This works great for most of the things I’ve done. But with specific things, mostly ones that return a big amount of information, the code dies out. I’ve narrowed it down to this section of the code:
Public Function Read() As List(Of String)
Dim output As New List(Of String)
Dim o = ""
Dim tmp(4) As Byte
Dim count As Long
While True
tmp(3) = tcpStream.ReadByte()
Select Case tmp(3)
Case 0
output.Add(o)
If o.Substring(0, 5) = "!done" Then
Exit While
Else
o = ""
Continue While
End If
Case Is < &H80
count = tmp(3)
Case Is < &HC0
count = BitConverter.ToInt32(New Byte() {tcpStream.ReadByte(), tmp(3), 0, 0}, 0) ^ &H8000
Case Is < &HE0
tmp(2) = tcpStream.ReadByte()
count = BitConverter.ToInt32(New Byte() {tcpStream.ReadByte(), tmp(2), tmp(3), 0}, 0) ^ &HC00000
Case Is < &HF0
tmp(2) = tcpStream.ReadByte()
tmp(1) = tcpStream.ReadByte()
count = BitConverter.ToInt32(New Byte() {tcpStream.ReadByte(), tmp(1), tmp(2), tmp(3)}, 0) ^ &HE0000000
Case &HF0
tmp(3) = tcpStream.ReadByte()
tmp(2) = tcpStream.ReadByte()
tmp(1) = tcpStream.ReadByte()
tmp(0) = tcpStream.ReadByte()
count = BitConverter.ToInt32(tmp, 0)
Case Else
Exit While 'err
End Select
For i = 0 To count - 1
o += ChrW(tcpStream.ReadByte())
Next
End While
Return output
End Function
Specifically, everything works when it is using this part (a small amount of data):
Case Is < &H80
count = tmp(3)
But I get an error if it makes it to this part:
Case Is < &HC0
count = BitConverter.ToInt32(New Byte() {tcpStream.ReadByte(), tmp(3), 0, 0}, 0) ^ &H8000
This part of the code is actually setting count = “Infinity”, so I’m sure thats not correct.
I’ve posted in some VB.Net forums and been trying to figure out exactly what this is doing but I’ve had no luck. If any of you have tackeled this or know where to point me I’d be very greatfull. Thanks!
–Usogi