Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Imports System.ComponentModel
- Public Class ConnectionValidater
- Inherits Component
- Public Event GotResult(ByVal address As String, ByVal success As Boolean)
- Public Structure connectattempt
- Public client As System.Net.Sockets.TcpClient
- Public address As String
- End Structure
- Private Sub OnConnect(ByVal value As System.IAsyncResult)
- Dim att As connectattempt = value.AsyncState
- Dim success As Boolean
- Try
- Dim s As System.Net.Sockets.NetworkStream = att.client.GetStream
- success = s.CanRead
- att.client.EndConnect(value)
- att.client.Close()
- s.Close()
- Catch
- success = False
- End Try
- RaiseEvent GotResult(att.address, success)
- End Sub
- Public Sub BeginValidating(ByVal address As String)
- Dim c As New connectattempt
- c.client = New System.Net.Sockets.TcpClient()
- c.address = address
- Dim port As Integer = 25565
- If address.Contains(":") Then
- Dim ps As String = address.Remove(0, address.IndexOf(":") + 1)
- If Not Integer.TryParse(ps, port) Then port = 25565
- address = address.Remove(address.Length - ps.Length - 1)
- End If
- c.client.BeginConnect(address, port, New System.AsyncCallback(AddressOf OnConnect), c)
- End Sub
- End Class
Add Comment
Please, Sign In to add comment