vb.net以太网通信 vb以太网通讯控件

VB与VB.NET串口及以太网通迅关于串口通讯vb.net以太网通信的问题vb.net以太网通信:
很明显vb.net以太网通信,vb.net以太网通信你还不知道(不会、不习惯)使用事件驱动的方式接收数据 。
建议vb.net以太网通信你仔细看看串口组件(无论VB6还是VB.net)的OnComm事件,你的问题很容易解决 。
关于以太网通讯:
在TCP通讯中端口确实可以重用,你百度一下“TCP端口重用”能查到很多示例 。
但绝大多数情况下不推荐端口重用,而应该采取服务器端建立连接池的方法 。
或者,干脆不用TCP , 用UDP解决也可以 。
用vb.net实现网络通信用 vb.net socket通信
Dim th As Threading.Thread
2Dim tcpl As System.Net.Sockets.TcpListener
3
4Private Sub Form1_Load()Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
5th = New System.Threading.Thread(New System.Threading.ThreadStart(AddressOf MyListen))
6th.Start()
7End Sub
8
9Public Sub SendMessage()Sub SendMessage(ByVal IP As String, ByVal SendMsg As String)
10Try
11If IP"" Then
12Dim tcpc As New System.Net.Sockets.TcpClient(IP, 5656)
13Dim tcpStream As Net.Sockets.NetworkStream = tcpc.GetStream
14Dim reqStream As New IO.StreamWriter(tcpStream)
15reqStream.Write(SendMsg)
16reqStream.Flush()
17tcpStream.Close()
18tcpc.Close()
19End If
20Catch ex As Exception
21MsgBox(ex.Message.ToString)
22End Try
23End Sub
24Private Sub MyListen()Sub MyListen()
25Try
26Dim ipAddress As System.Net.IPAddress = System.Net.Dns.Resolve(System.Net.Dns.GetHostName).AddressList(0)
27tcpl = New System.Net.Sockets.TcpListener(ipAddress, 5656)
28tcpl.Start()
29While True
30Dim s As System.Net.Sockets.Socket = tcpl.AcceptSocket()
31Dim MyBuffer(1024) As Byte
32Dim i As Integer
33i = s.Receive(MyBuffer)
34If i0 Then
35Dim lstrRec As String
36Dim j As Integer
37For j = 0 To i - 1
38TextBox1.Text += Chr(MyBuffer(j))","
39Next
40End If
41End While
42Catch ex As Exception
43MsgBox(ex.Message.ToString)
44End Try
45End Sub
46
47Private Sub Button1_Click()Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
48SendMessage("192.168.0.61", TextBox2.Text)
49End Sub
能给我发个VB与三菱PLC通讯的源代码实例吗,非常感谢啊得说明是什么型号的PLC?。诨故峭? ,VB6还是VB.NET?
算了,写段代码 , VB.NET与Q系列以太网通讯的:
Imports System.Net
Imports System.Runtime.InteropServices
Public Class Form1
Dim Handle1 As Int32
Dim EntLink1 As Boolean
Dim ScanCount1 As Long
Dim PLC As New EntQsPlc_Asc.PlcClient'EntQsPlc_ASC.DLL是Q系列以太网通讯组件
Public Declare Function timeGetTime Lib "winmm.dll" () As UInt32
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Me.CenterToScreen()
cmbReadMry.Items.Clear()
cmbReadMry.Items.Add("X")
cmbReadMry.Items.Add("Y")
cmbReadMry.Items.Add("M")
cmbReadMry.Items.Add("D")
cmbReadMry.Items.Add("R")
cmbReadMry.Items.Add("Z")
'
cmbWriteMry.Items.Clear()
cmbWriteMry.Items.Add("X")
cmbWriteMry.Items.Add("Y")
cmbWriteMry.Items.Add("M")
cmbWriteMry.Items.Add("D")
cmbWriteMry.Items.Add("R")
cmbWriteMry.Items.Add("Z")
'
cmbBitMry.Items.Clear()
cmbBitMry.Items.Add("X")
cmbBitMry.Items.Add("Y")
cmbBitMry.Items.Add("M")
'
cmbReadType.Items.Clear()
cmbReadType.Items.Add("INT16")
cmbReadType.Items.Add("UINT16")

推荐阅读