全局代码Public ClientSocket As New System.Net.Sockets.Socket(System.Net.Sockets.AddressFamily.InterNetwork,System.Net.Sockets.SocketType.Stream, System.Net.Sockets.ProtocolType.Tcp)
Public remoteEP As New System.Net.IPEndPoint(System.Net.IPAddress.Parse("127.0.0.1"),502)
Public IsRun As Boolean = False
Public ClientThread As System.Threading.Thread
连接按键
try
ClientSocket.Connect(remoteEP)
ClientThread = New System.Threading.Thread(AddressOf ReciveMsg)
ClientThread.Start()
Catch ex As Exception
messagebox.show("未能正常连接!")
End try
定义了一个计划
Dim dianwen(11) As Byte
dianwen(0) = &H00
dianwen(1) = &H00
dianwen(2) = &H00
dianwen(3) = &H00
dianwen(4) = &H00
dianwen(5) = &H06
dianwen(6) = &H00
dianwen(7) = &H03
dianwen(8) = &H00
dianwen(9) = &H80
dianwen(10) = &H00
dianwen(11) = &H14
Dim bytesSent As Integer = ClientSocket.Send(dianwen)
发现不能长时间运行,用的本地端口测试,也没有说网络不稳定啥的呀。。为什么运行几个小时后软件就闪退了。。
[此贴子已经被作者于2020/12/22 11:26:26编辑过]