Public netStream As NetworkStream
Public tcpClient As System.Net.Sockets.TcpClient
Dim IPaddr As IPAddress = IPAddress.Parse(IP)
Dim Epoint As New IPEndPoint(IPaddr, PART)
连接:
tcpClient = New tcpClient
tcpClient.Connect(Epoint)
netStream = tcpClient.GetStream()
rdStream = New StreamReader(netStream)
wtStream(GWcode) = New StreamWriter(netStream)
接受:
Dim ATimer As New System.Timers.Timer(100)
在窗体加载时:
ATimer.Enabled = True
AddHandler ATimer.Elapsed, AddressOf TcpEvent01
托管:
Private Sub TcpEvent01(ByVal source As Object, ByVal e As ElapsedEventArgs)
Dim strData(512) As Byte ' Max Receiving Data Length
Dim Adocont As Short
Dim tmpv As Object
Dim tmpstr As String
Dim bytes(tcpClient.ReceiveBufferSize) As Byte
netStream(lnCode) = tcpClient(lnCode).GetStream
If netStream(lnCode).DataAvailable = True Then
netStream(lnCode).Read(bytes, 0, CInt(tcpClient(lnCode).ReceiveBufferSize))
Dim i As Integer
Dim str As String
For i = 0 To 100
str = str & bytes(i)
Next
tmpstr = HexOp3(bytes, 0, CShort(100))
If Microsoft.VisualBasic.Left(tmpstr, 13) = "Communication" Then
Exit Function
GC.Collect(2)
End If
StObj.LnCode = lnCode
StObj.Info = tmpstr
'Tpool.QueueUserWorkItem(New System.Threading.WaitCallback(AddressOf DWdate), StObj)
GC.Collect(2)
End If
End Sub