早上好,我正在一个项目中,我需要从其他ESP8266接收信息,并需要通过一个应用程序来处理此数据。
我正在考虑使用Sockets进行操作,看起来很多,我有一个功能代码,但是它仅从客户端接收信息。我想知道是否有人可以帮助我知道我可以对此代码进行哪些更改,以便接收更多ESP的数据。通信的代码库如下:
Public Class Form1
Dim TCPServer As Socket
Dim TCPListener As TcpListener
Dim ip As String
Public ipserver As IPAddress = IPAddress.Parse("192.168.137.1")
Public IsListening As Boolean = True
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
TCPListener = New TcpListener(IPAddress.Any, 80) 'esp
TCPListener.Start()
TCPServer = TCPListener.AcceptSocket()
TCPServer.Blocking = False
Timer1.Enabled = True
End Sub
Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
Try
Dim Rcvbytes(TCPServer.ReceiveBufferSize) As Byte
TCPServer.Receive(Rcvbytes)
TextBox2.Text = (System.Text.Encoding.ASCII.GetString(Rcvbytes))
Catch ex As Exception
End Try
End Sub
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
Dim sendbytes() As Byte = (System.Text.Encoding.ASCII.GetBytes(TextBox1.Text))
TCPServer.Send(sendbytes)
TextBox1.Clear()
End Sub
End Class