Vb的网络错误40006或者40020错误或者10048错误
毕设基于以太网的蓝牙多点测温系统,stm32做服务器,将采集的温度通过以太网送到PC端,PC做客户端,可以通过以太网设置温度,保存成excel和进行折线图的绘制,但是由于...
毕设基于以太网的蓝牙多点测温系统,stm32做服务器,将采集的温度通过以太网送到PC端,PC做客户端,可以通过以太网设置温度,保存成excel和进行折线图的绘制,但是由于能力问题用起来失灵时不灵,会出现40006和40020错误和10048错误,求大神指教,基本上连接一次再等一会就可以用了
因字数问题删掉了部分无关紧要的部分Private Sub Command1_Click() ‘连接按键If tcpClient.State <> 0 Then tcpClient.Close End IftcpClient.ConnectTimer1.Enabled = True ’开启定时器,定时发送POST采集温度Command1.Enabled = False ’连接按键失能,防止误操作End SubPrivate Sub Command2_Click() ‘保存成excel表格end subPrivate Sub Command4_Click()tcpClient.SendData "B点" + Text2.TextEnd SubPrivate Sub Command5_Click()Timer1.Enabled = FalseForm2.Visible = TrueEnd SubPrivate Sub Form_Load() ‘初始化服务器IP,端口和listview tcpClient.RemoteHost = "192.168.1.18" tcpClient.RemotePort = 2060tcpClient.LocalPort = Rnd ’网上说端口被占用的原因,所以加了个这个还是不行Text3.Text = 0Command5.Enabled = False Text4.Text = ""End SubPrivate Sub Form_Unload(Cancel As Integer) If tcpClient.State <> 0 Then ‘退出时关闭winsock tcpClient.Close End IfEnd Sub'添加数据到listview1中Private Sub tcpClient_DataArrival _(ByVal bytesTotal As Long) Dim strData As String tcpClient.GetData strData Text5.Text = strData Dim XX = ListView1.ListItems.Count + 1ListView1.ListItems.Add , , XListView1.ListItems(X).SubItems(1) = Mid(Text5.Text, 3, 2) & "." & Mid(Text5.Text, 5, 2)ListView1.ListItems(X).SubItems(2) = Mid(Text5.Text, 9, 2) & "." & Right(Text5.Text, 2)ListView1.ListItems(X).SubItems(3) = Hour(Time) & ":" & Minute(Time) & ":" & Second(Time)ListView1.ListItems(X).SubItems(4) = Text4.TextText3.Text = Text3.Text + 1 ’当收到十个以上的数据时绘图功能开启,技术渣只能通过text3来做全局变量If Text3.Text > 10 ThenCommand5.Enabled = TrueEnd IfEnd SubPrivate Sub Text1_KeyPress(KeyAscii As Integer) ‘温度设置的过滤,保证输入的是数字End IfEnd SubPrivate Sub Text2_KeyPress(KeyAscii As Integer) ‘温度设置的过滤,保证输入的是数字End SubPrivate Sub Timer1_Timer() ’定时发送POST字符,Text4用于记录发送时间,技术渣tcpClient.SendData "POST"Text4.Text = Hour(Time) & ":" & Minute(Time) & ":" & Second(Time)End Sub代码就这些,求大神帮忙
更多0 展开
因字数问题删掉了部分无关紧要的部分Private Sub Command1_Click() ‘连接按键If tcpClient.State <> 0 Then tcpClient.Close End IftcpClient.ConnectTimer1.Enabled = True ’开启定时器,定时发送POST采集温度Command1.Enabled = False ’连接按键失能,防止误操作End SubPrivate Sub Command2_Click() ‘保存成excel表格end subPrivate Sub Command4_Click()tcpClient.SendData "B点" + Text2.TextEnd SubPrivate Sub Command5_Click()Timer1.Enabled = FalseForm2.Visible = TrueEnd SubPrivate Sub Form_Load() ‘初始化服务器IP,端口和listview tcpClient.RemoteHost = "192.168.1.18" tcpClient.RemotePort = 2060tcpClient.LocalPort = Rnd ’网上说端口被占用的原因,所以加了个这个还是不行Text3.Text = 0Command5.Enabled = False Text4.Text = ""End SubPrivate Sub Form_Unload(Cancel As Integer) If tcpClient.State <> 0 Then ‘退出时关闭winsock tcpClient.Close End IfEnd Sub'添加数据到listview1中Private Sub tcpClient_DataArrival _(ByVal bytesTotal As Long) Dim strData As String tcpClient.GetData strData Text5.Text = strData Dim XX = ListView1.ListItems.Count + 1ListView1.ListItems.Add , , XListView1.ListItems(X).SubItems(1) = Mid(Text5.Text, 3, 2) & "." & Mid(Text5.Text, 5, 2)ListView1.ListItems(X).SubItems(2) = Mid(Text5.Text, 9, 2) & "." & Right(Text5.Text, 2)ListView1.ListItems(X).SubItems(3) = Hour(Time) & ":" & Minute(Time) & ":" & Second(Time)ListView1.ListItems(X).SubItems(4) = Text4.TextText3.Text = Text3.Text + 1 ’当收到十个以上的数据时绘图功能开启,技术渣只能通过text3来做全局变量If Text3.Text > 10 ThenCommand5.Enabled = TrueEnd IfEnd SubPrivate Sub Text1_KeyPress(KeyAscii As Integer) ‘温度设置的过滤,保证输入的是数字End IfEnd SubPrivate Sub Text2_KeyPress(KeyAscii As Integer) ‘温度设置的过滤,保证输入的是数字End SubPrivate Sub Timer1_Timer() ’定时发送POST字符,Text4用于记录发送时间,技术渣tcpClient.SendData "POST"Text4.Text = Hour(Time) & ":" & Minute(Time) & ":" & Second(Time)End Sub代码就这些,求大神帮忙
更多0 展开
展开全部
tcpClient.RemoteHost = "192.168.1.18"
tcpClient.RemotePort = 2060
去掉 tcpClient.LocalPort = Rnd,让winsock控件自动选择本机的空闲的端口
追问
原先不加这个也是这个情况,现在的情况是过一段时间就可以用了,但是关闭后立即连接就会提示地址被占用,还要麻烦你了
追答
Option Explicit
Private Sub Command1_Click()
Winsock1.Connect
Command1.Enabled = False
Command2.Enabled = True
End Sub
Private Sub Command2_Click()
Winsock1.SendData Text1.Text
End Sub
Private Sub Form_Load()
With Winsock1
'本地
.Protocol = sckTCPProtocol
.LocalPort = 0 'port =0 表示任意
'远程
.RemoteHost = "192.168.1.20"
.RemotePort = 8080
End With
End Sub
Private Sub Form_Unload(Cancel As Integer)
'无论Connect与否,都需关闭!
Winsock1.Close
End Sub
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询