你好
我在车队管理Web应用程序的工作,我有很多GPSS他们它们的数据包发送到我的网站。
所以,我应该有一个监听器得到这个包。
我写了下面的类,但它是如此薄弱。有时听到,有时不..
我需要有强大的东西。
Imports System.Threading
Imports System
Imports System.IO
Imports System.Net
Imports System.Net.Sockets
Imports System.Text
Imports Microsoft.VisualBasic
Public Class cls_GPRS_Business
Private trd As Thread
Private Mo_Positions As New cls_Positions_Business
Public Sub ListenGPRS()
Dim TCPserver As TcpListener
TCPserver = Nothing
Try
' Set the TcpListener on port 13000.
TCPserver = New TcpListener(1688)
' Start listening for client requests.
TCPserver.Start()
' Buffer for reading data
Dim bytes(1024) As Byte
Dim data As String = Nothing
' Enter the listening loop.
Do
' Perform a blocking call to accept requests.
' You could also user server.AcceptSocket() here.
Dim client As TcpClient = TCPserver.AcceptTcpClient()
data = Nothing
' Get a stream object for reading and writing
Dim stream As NetworkStream = client.GetStream()
Dim i As Int32
' Loop to receive all the data sent by the client.
i = stream.Read(bytes, 0, bytes.Length)
data = System.Text.Encoding.ASCII.GetString(bytes, 0, i)
Mo_Positions.InsertGPRS(data.Trim)
client.Close()
Thread.Sleep(100)
Loop
Catch e As SocketException
'SaveTextFile(Server.MapPath("test.txt"), e.Message & vbCrLf)
Finally
TCPserver.Stop()
End Try
End Sub
Public Sub StartGPRS()
trd = New Thread(AddressOf ListenGPRS)
trd.IsBackground = True
trd.Start()
End Sub
End Class
任何人都可以把我的想法吗?
最好的问候。