用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.NET 如何通过TCP/IP协议通讯实现16进制数据的接收?传输Integer 数据类型来传输比较方便.因为Integer 的取值可以是0x0000-0xFFFF .当你把数据发送到目的主机后可以利用Hex() 把接收到的数据从十进制转换到十六进制..
VB.NET串口通讯怎么发送和接收十六进制?串口通信最终都是用二进制传输的,你用代码把二进制转化成十六进制就可以了 。不需要额外设置 。
【vb.net传输帧格式的简单介绍】vb.net传输帧格式的介绍就聊到这里吧,感谢你花时间阅读本站内容,更多关于、vb.net传输帧格式的信息别忘了在本站进行查找喔 。
推荐阅读
- 英文放置经营游戏暗黑,好玩的放置经营游戏
- chatgpt写量化策略,量化策略app
- oracle查看数据库启动时间同步,oracle数据库查看实例启动状态
- python三大基础函数 python三大基础结构
- go语言加载lua,go语言加载bin
- 最好玩的华乐棋牌游戏的简单介绍
- sapcogi,sapCOGI盘盈盘亏
- 怎么挂进程oracle oracle挂载dbf
- jquery获取ul下所有li,jquery获取ul li的值