怎样使用winsock控件发送两个数据,中间间隔1秒

jacklee19822001 2006-12-06 10:41:21
winsock控件用于网络发送指令到客户端
希望发送两条指令,中间间隔1秒
WinSock1.SendData Cmd1
'间隔1秒
WinSock1.SendData cmd2

如果使用sleep后
第一次senddata时,客户端收不到任何东西,等到发送第二条指令时,客户端一下子收到了2条指令

不知道怎么解决这个问题
这到底是怎么回事?
高手能告诉我解决方案么?
...全文
357 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
fj182 2007-03-02
  • 打赏
  • 举报
回复
Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
Private Declare Function GetTickCount Lib "kernel32" () As Long

Private Sub Command1_Click()

Winsock1.SendData cmd1
DoEvents
Wait 1000
Winsock1.SendData cmd2
DoEvents

End Sub

Public Sub Wait(ByVal dwMilliseconds As Long)

Dim t As Long

t = GetTickCount()

Do While (GetTickCount() < t + dwMilliseconds)
Sleep 1
Loop

End Sub
terrywolf 2007-03-02
  • 打赏
  • 举报
回复
LZ赶紧出来给分啊,别忘了给我一份啊!
ZOU_SEAFARER 2007-03-01
  • 打赏
  • 举报
回复
WinSock1.SendData Cmd1
'间隔1秒
'自己写一个函数,WAIT
call wait1000

WinSock1.SendData cmd2
Option Explicit
Private Declare Function GetTickCount Lib "kernel32" () As Long


Public Sub wait1000()
Dim StartNum As Long
Dim EndNum As Long
StartNum = GetTickCount
DoEvents
LL: EndNum = GetTickCount
DoEvents
If EndNum - StartNum >= 1000 Then
Exit Sub
Else
GoTo LL
End If

End Sub
zyg0 2007-03-01
  • 打赏
  • 举报
回复
doevents
VirtualDesktop 2007-02-28
  • 打赏
  • 举报
回复
用个timer不可以么?
terrywolf 2007-02-28
  • 打赏
  • 举报
回复
顶一下,浮上来
yj5354 2006-12-07
  • 打赏
  • 举报
回复
'加一个Timer 控件,设定Timer1.Interval = 1000
'代码如下:
Dim cmd(1) As String
Private Sub Timer1_Timer()
Static i As Integer
sendD i
i = i + 1
If i > 2 Then Timer1.Enabled = False: i = 0
End Sub

Private Sub sendD(i As Integer)
WinSock1.SendData cmd(i)
End Sub

Private Sub Command1_Click()
Timer1.Interval = 1000
Timer1.Enabled = True
End Sub
jacklee19822001 2006-12-07
  • 打赏
  • 举报
回复
无人关心??:-(

1,502

社区成员

发帖
与我相关
我的任务
社区描述
VB 网络编程
社区管理员
  • 网络编程
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧