UDP Client Lockup

Ontani

Centurion
Joined
Mar 3, 2004
Messages
121
Location
Belgium
hey i'm make an application with a udp client.
but got the problem that the application gets locked up when i click the button btnGetStatus fast after eachother.
is there a way to let the udp client only start if the other one is closed?

my Code:

Visual Basic:
Dim currentPlayers(1, 10) As String
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        getCurrentStatus()
    End Sub

    Public Function getCurrentStatus()
        Try
            Dim udp As New UdpClient("81.11.182.187", "20102")
            Dim i, j As Integer
            Dim b() As Byte = System.Text.Encoding.Default.GetBytes("ÿÿÿÿrcon ssfownsall status")
            udp.Send(b, b.Length)
            Dim thisIP As New System.Net.IPEndPoint(IPAddress.Parse("81.11.182.187"), 0)
            Dim allInfo As String
            Dim endChar As String
            Dim player As String
            Dim status() As String
            Dim r() As Byte
            For i = 0 To 8
                r = udp.Receive(thisIP)
                allInfo = System.Text.ASCIIEncoding.Default.GetString(r)
                If i = 0 Then
                    endChar = Mid(allInfo, 10, 1)
                End If
                allInfo = allInfo.Replace("ÿÿÿÿprint" & endChar, "")
                allInfo = allInfo.Replace(endChar, vbCrLf)
                If i > 2 Then
                    getIdIp(allInfo)
                End If
            Next
            'when this For Next is completed the array currentPlayers is filled with id's and ip's
            udp.Close()
        Catch
        End Try
    End Function

    Public Function getIdIp(ByVal playerString As String)
        Dim id As String = CType(Mid(playerString, 3, 1), Integer)
        Dim removeString As String = Mid(playerString, playerString.LastIndexOf(":") + 1, playerString.Length - playerString.LastIndexOf(":") + 1)
        playerString = playerString.Replace(removeString, "")
        Dim ip As String = Mid(playerString, playerString.LastIndexOf(" ") + 2, playerString.Length - playerString.LastIndexOf(" "))
        currentPlayers(0, id) = id
        currentPlayers(1, id) = ip
        TextBox1.Text &= currentPlayers(0, id) & " - " & currentPlayers(1, id) & vbCrLf
    End Function

    Private Sub btnGetStatus_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        TextBox1.Text = ""
        getCurrentStatus()
    End Sub

Normal response in this case is:
Code:
0 - 81.11.182.187
1 - 81.132.2.105
2 - 80.220.234.233
3 - 80.2.220.91
4 - 213.119.180.21
5 - 81.164.97.125

somone an idea?
 
yeah i know, i did that, but what if i want to call it as a function, and its called 2 times fast after eachother
 
Back
Top