none
如何計時廣播訊息? RRS feed

  • 問題

  • 寫了一個udp廣播程式,想要每隔十秒鐘發送一次,可是接收端好像每隔三秒就收到一次,不知道那裡有問題?還是這樣子寫是錯的?

    ------------------------------------------------------------------------------------------------------- 

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            uc = New UdpClient(CInt(txtLocalPort.Text))
            GroupAddress = IPAddress.Parse(txtServerName.Text)
            RemoteEP = New IPEndPoint(GroupAddress, CInt(txtRemotePort.Text))
            rT = New Threading.Thread(AddressOf Sending)
            rT.Start()
            TextBox3.Text = "啟動發送電子折價券伺服器"
            Label10.Hide()
              End Sub

       Public Sub Sending()
            Try

                While bKeepRunning
                    Thread.Sleep(2000)
                                  While cKeepRunning = False
                        Label6.Text = "Start Send The Messages"
                        Dim sendBytes As [Byte]() = Encoding.Unicode.GetBytes(TextBox2.Text)
                        uc.Send(sendBytes, sendBytes.Length, RemoteEP)
                        TextBox1.Text = "發送電子折價券"   

    While cKeepRunning = True
                            TextBox1.Text = "暫停發送電子折價券" 

                     End While
                    End While
                End While
            Catch ex As Exception
                RaiseEvent Sock_Error(ex.ToString)
            End Try

        End Sub

     Private Sub Timer1_Elapsed(ByVal sender As System.Object, ByVal e As System.Timers.ElapsedEventArgs) Handles Timer1.Elapsed
            If cKeepRunning = False Then
                cKeepRunning = True
                Label6.Text = "Pause"
            Else
                cKeepRunning = False
                Label6.Text = "Start Send The Messages"
            End If
        End Sub

    2006年10月19日 上午 07:30

解答

所有回覆

  • 你 Thread.Sleep() 才下二秒鐘 ... 把 2000 加到 10000 看看 .
    2006年10月19日 上午 08:28
    版主
  • 我之前就有試過將 Thread.Sleep(2000)改成10秒,

    可是clinet還是一樣每三秒就會收到,不過我有用封包監視軟體,

    server是每隔十秒發送一次,不知道是那裡出了問題...

    也試過將發送訊息程式寫在Timer1裡,可是好像就變成沒有廣播了..

    2006年10月20日 上午 07:48