1

私はこれに数日間取り組んでおり、車輪を回転させているところです。これは、mikrotik ルーターの API に接続するための vb.net コードの一部です。彼らのwikiで提供されていましたが、ポップアップするエラーがあり、答えを見つけるのに苦労しています.

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

ほとんどの場合、これを実行するとすべて正常に動作しますが、応答が長すぎるとエラーが発生します。少なくともそれが原因だと思います。コードが到達した場合

count = BitConverter.ToInt32(New Byte() {tcpStream.ReadByte(), tmp(3), 0, 0}, 0) ^ &H8000

「算術演算でオーバーフローが発生しました」というメッセージが表示されます

これがどのように機能しているのかはわかりますが、ここで何が起こっているのかを正確に把握していません. tcpStream.ReadByte() は 143 を返しています

tmp(3) は 128 を返しています

BitConverter.ToInt32(New Byte() {tcpStream.ReadByte(), tmp(3), 0, 0}, 0) ^ &H8000 は「Infinite」を返していますが、これが問題だと思います。

完全なコードに興味がある場合は、ここで見つけることができます: http://wiki.mikrotik.com/wiki/API_in_VB_dot_NET

何が悪いのか誰も教えてくれないのなら、このコードの塊が何をしているのか知りたいだけです...コードにコメントしてくれたらいいのに= P

どうもありがとうございました

4

0 に答える 0