Quantcast
Channel: VBForums - Visual Basic .NET
Viewing all articles
Browse latest Browse all 27554

Try, Retry

$
0
0
I have code which tries to connect a chat client to a server and if it fails, exits the application. I'm now trying to get the program to wait 2 mins and try again. I was thinking of starting a timer in the exception which would then make a call back to my function so that it keeps looping every 2mins until it actually connects. Any better suggestions/solutions?

Code:

    Public Function ConnectToRemote(ByVal IP As IPAddress, ByVal port As Integer) As Boolean
        Dim soc As New Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp)
        Try
            soc.Connect(New IPEndPoint(IP, port))

            g_socConnected = soc

            BeginWaitForChat()
            Return True
        Catch ex As Exception
            Application.Exit()
        End Try
    End Function


Viewing all articles
Browse latest Browse all 27554

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>