Jump to content
Xtreme .Net Talk

Recommended Posts

  • Leaders
Posted

you would need to catch a " port already in use " error ( then maybe loop back to your connecting code to try a different port )

to test for an open / used port you could do something along these lines...

       Try
           Dim ip As System.Net.IPHostEntry = System.Net.Dns.GetHostByName(System.Net.Dns.GetHostName())
           Dim ipaddy As Net.IPAddress = ip.AddressList(0)
           Dim ep As New Net.IPEndPoint(ipaddy, 80)
           Dim listner As New Net.Sockets.TcpListener(ep)
           listner.Start()

       Catch ex As SocketException
           If ex.ErrorCode = 10048 Then '/// error number for Port already in use.
               MessageBox.Show("The port you attempted to connect to is already in use!")
           Else
               MessageBox.Show(ex.ErrorCode & "   " & ex.Message)
           End If
       End Try

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...