⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 wmclient.vb

📁 本源码是用VB开发的GPS追踪定位系统。
💻 VB
字号:
Imports System.Net.Sockets

Public Class WMClient
    Public Event LatLng(ByVal ID As Integer, ByVal lat As Double, ByVal lng As Double)

    Private _client As TcpClient
    '---used for sending/receiving data---
    Private data() As Byte

    Public Sub New(ByVal client As TcpClient)
        _client = client
        '---start reading data from the client in a separate thread---
        ReDim data(_client.ReceiveBufferSize)
        _client.GetStream.BeginRead(data, 0, _
           CInt(_client.ReceiveBufferSize), _
           AddressOf ReceiveMessage, Nothing)
    End Sub

    Public Sub ReceiveMessage(ByVal ar As IAsyncResult)
        '---read from client---
        Dim bytesRead As Integer
        Try
            SyncLock _client.GetStream
                bytesRead = _client.GetStream.EndRead(ar)
            End SyncLock
            '---client has disconnected---
            If bytesRead < 1 Then
                Exit Sub
            Else
                '---get the message sent---
                Dim messageReceived As String = _
                    System.Text.Encoding.ASCII. _
                    GetString(data, 0, bytesRead)
                Dim field() As String = messageReceived.Split(":")
                '---raise an event to pass back the lat and lng---
                RaiseEvent LatLng(field(0), Convert.ToDouble(field(1)), Convert.ToDouble(field(2)))
            End If
            '---continue reading from client---
            SyncLock _client.GetStream
                _client.GetStream.BeginRead(data, 0, _
                   CInt(_client.ReceiveBufferSize), _
                   AddressOf ReceiveMessage, Nothing)
            End SyncLock
        Catch ex As Exception
            Console.WriteLine(ex.ToString)
        End Try
    End Sub
End Class

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -