Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How can I get the server status???
#3
Checking if the computer is conected to the internet:

[code2=vbnet]If My.Computer.Network.IsAvailable = True Then
MsgBox("Your computer is conected", MsgBoxStyle.OkOnly Or MsgBoxStyle.Information, "Information")
Else
MsgBox("Your computer is not conected", MsgBoxStyle.OkOnly Or MsgBoxStyle.Critical, "Information")
End If[/code2]

Pinging a host:

First import System.Net and System.Net.NetworkInformation:


[code2=vbnet]Imports System.Net, System.Net.NetworkInformation[/code2]
Then ping with the folowing code:
[code2=vbnet]Sub Ping()

Dim ping As New Ping()
Dim reply As PingReply
Dim _byte As Byte() = BitConverter.GetBytes(32)

Try
reply = ping.Send(Host, 1000, _byte)

Select Case reply.Status
Case IPStatus.Success
' code for succesfull ping
Case IPStatus.TimedOut
' code for ping timeout
Case IPStatus.BadDestination
'code for bad adress
Case Else
'code for other ocurences
' you can put a MsgBox that will say that something else happened
'MsgBox("Please check code", MsgBoxStyle.Exclamation, "Ping Status")
End Select

Catch pex As PingException
MsBox(pex.ToString)
Exit Sub
Catch ex As Exception
MsgBox(ex.ToString)
End Try[/code2]

Now before you reply to this post saying that the code above does not work replace "Host" with the actual ip of the web site.

For the third problem , checking if MySql server is online or not, that is also simple because usualy MySql has a default port number and its just a case of connecting a TcpClient to that ip and port and if it connects it means it is online.

Here are the steps to do just that:
First , just as above import System.Net And System.Net.Sockets(i'm not going to show how to do it again)

Second Use this code snippet:

[code2=vbnet]Private Sub CheckServerStatus()
Try
Dim TcpCl As New TcpClient
Dim IpEP As New IPEndPoint(IPAddress.Parse("IP"), 3306) 'if i'm not mistaking 3306 is the default port for Mysql Server
TcpCl.Connect(IpEP)
If TcpCl.Connected Then
'code for serve online
TcpCl.Close()
End If
Catch ex As Exception
'code for server offline
End Try
End Sub[/code2]

Replace "IP" with the ip of the server you are trying to connect. REMEMBER THE "IP" HAS TO BE A STRING !!!
Sssssssssoftware developer...


Messages In This Thread
How can I get the server status??? - by mnxford - 03-25-2013, 11:44 AM
Re: How can I get the server status??? - by Snake_eyes - 03-26-2013, 09:57 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  multiple csv files add sql server tables via VB.NET secilsengul 1 9,974 04-16-2014, 10:27 AM
Last Post: brco900033
  Downloading from FTP server doesn't work brco900033 5 21,848 08-16-2013, 04:32 AM
Last Post: brco900033
  Is this possible with SQL Server? Worf 2 12,336 02-25-2013, 03:04 AM
Last Post: Worf
  Sockets Programming(Disconnecting from Server) xolara 1 9,432 04-06-2012, 01:47 PM
Last Post: brandonio21

Forum Jump:


Users browsing this thread: 1 Guest(s)