Guest User

Untitled

a guest
Jan 19th, 2019
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.38 KB | None | 0 0
  1. Imports System.ComponentModel
  2.  
  3. Public Class ConnectionValidater
  4. Inherits Component
  5. Public Event GotResult(ByVal address As String, ByVal success As Boolean)
  6.  
  7. Public Structure connectattempt
  8. Public client As System.Net.Sockets.TcpClient
  9. Public address As String
  10. End Structure
  11.  
  12. Private Sub OnConnect(ByVal value As System.IAsyncResult)
  13. Dim att As connectattempt = value.AsyncState
  14.  
  15. Dim success As Boolean
  16. Try
  17. Dim s As System.Net.Sockets.NetworkStream = att.client.GetStream
  18. success = s.CanRead
  19. att.client.EndConnect(value)
  20. att.client.Close()
  21. s.Close()
  22. Catch
  23. success = False
  24. End Try
  25. RaiseEvent GotResult(att.address, success)
  26. End Sub
  27.  
  28. Public Sub BeginValidating(ByVal address As String)
  29. Dim c As New connectattempt
  30. c.client = New System.Net.Sockets.TcpClient()
  31. c.address = address
  32. Dim port As Integer = 25565
  33. If address.Contains(":") Then
  34. Dim ps As String = address.Remove(0, address.IndexOf(":") + 1)
  35. If Not Integer.TryParse(ps, port) Then port = 25565
  36. address = address.Remove(address.Length - ps.Length - 1)
  37. End If
  38. c.client.BeginConnect(address, port, New System.AsyncCallback(AddressOf OnConnect), c)
  39. End Sub
  40. End Class
Add Comment
Please, Sign In to add comment