Sub Class_Globals
Private sock As Socket
Private Astream As AsyncStreams
Private response As String
Private su As StringUtils
Private mHost As String
Private mCallback As Object
Private mEventName As String
End Sub
Public Sub Initialize(Callback As Object, EventName As String)
mCallback = Callback
mEventName = EventName
End Sub
Public Sub Connect(IPAddress As String, Port As Int, Username As String, Password As String)
If Astream.IsInitialized Then Astream.Close
sock.Initialize("sock")
sock.Connect(IPAddress, Port, 30000)
mHost = IPAddress
Dim credentials As String = Username & ":" & Password
Dim Data() As Byte = credentials.GetBytes("UTF8")
Dim auth As String = su.EncodeBase64(Data)
response = $"GET / HTTP/1.1
Host: ${IPAddress}
Ntrip-Version: Ntrip/2.0
User-Agent: NTRIP Client
Accept: */*
Authorization: Basic ${auth}
Connection: close
"$
End Sub
Private Sub Sock_Connected(Successful As Boolean)
If Successful Then
Astream.Initialize(sock.InputStream, sock.OutputStream, "astream")
Log("Request message: " & response)
Astream.Write(response.GetBytes("UTF8"))
Log(response.GetBytes("UTF8"))
Else
Log("Connection failed")
CallSubDelayed2(mCallback, mEventName & "_ConnectionFailed", True)
End If
End Sub
Private Sub AStream_NewData(Buffer() As Byte)
Dim receivedData As String = BytesToString(Buffer, 0, Buffer.Length, "UTF8")
Log("Received Data Chunk: " & receivedData)
response = response & receivedData
End Sub
Private Sub Astream_Terminated
Log("Connection terminated. Full response: " & response)
' Process the response here
Dim mountPoints As List = ParseMountPoints(response)
CallSubDelayed2(mCallback, mEventName & "_MountPointsReceived", mountPoints)
End Sub
Private Sub ParseMountPoints(Response1 As String) As List
Dim mountPoints As List
mountPoints.Initialize
Dim lines() As String = Regex.Split(CRLF, Response1)
For Each line As String In lines
If line.StartsWith("STR;") Then ' NTRIP response contains lines starting with "STR;" for mount points
mountPoints.Add(line)
End If
Next
Return mountPoints
End Sub