Winsock的循环发送命令问题,请高人指点,虚心求学
小白我编程了一个小软件是和单片机交互的,我向单片机发命令,他回给我一条回复。现在遇到是问题是,1.如果我用循环发命令,比如FOR循环,如何能实现在接到回复后,在发下一条呢?
2.VB 的socket有没有延时机制呢?
For i = a To b或者在DataArrival件事里再发下一个数据。
Winsock1.SendData Data
DoEvents
Next
Private Sub Winsock1_DataArrival(ByVal bytesTotal As Long)
Winsock1.SendData Data
End Sub
楼上的正解。
Dim f As Boolean
Private Sub Command1_Click()
Dim i As Integer, x As String
Winsock1.SendData x
For i = 1 To 20
While Not f
DoEvents
Wend
....
....
Winsock1.SendData x
f = False
Next
End Sub
Private Sub Winsock1_DataArrival(ByVal bytesTotal As Long)
Dim data1 As String
Winsock1.GetData data1
....
....
If data1符合要求 Then f = True
End Sub
补充:VB , 网络编程