hi all,
i wanted to give you a code for vb 2010 to show it the server is online or offline
first for the imports
Code:
Imports System.Net.Sockets
then under the Public Class Form1 insert this code
Code:
Dim game As New TcpClient()
Dim auth As New TcpClient()
the game dim is for the game server state and auth is for auth server state
then for the code of the status you can but it any were you want in the form load if you want it to see if the the server is off or on when the launcher is started or in a button so the player can manual see it
you will need also two labels to in your form
Try
game.Connect("gameserver ip", game server port example {4515} )
Catch ex As Exception
label1.Text = "Offline"
label1.ForeColor = Color.Red
End Try
Try
auth.Connect("authserver ip",port example {1433} )
Catch ex As Exception
label2.Text = "Offline"
label2.ForeColor = Color.Red
End Try
If game.Connected Then
label1.Text = "Online"
label1.ForeColor = Color.Green
End If
If auht.Connected Then
label2.Text = "Online"
label2.ForeColor = Color.Green
End If
and this is the link for the FULL launcher just edit the IP and PORT
download form : Screenshoots
if it's not online
Just as an tip: Try to build it like this (C# code):
Code:
try{
auth.Connect();
if(auth.Connected){
// Do Something
auth.Close(); // Close Socket !important!
}
}catch{
// Do something (offline)
}
So you have that in 1 part.
like you hate Visual Basic I hate C# and C++
I spent days trying to find a code for the browser and did not succeed that way i hate them they are very hard to learn
but Nice
Just as an tip: Try to build it like this (C# code):
Code:
try{
auth.Connect();
if(auth.Connected){
// Do Something
auth.Close(); // Close Socket !important!
}
}catch{
// Do something (offline)
}
So you have that in 1 part.
Always put the connection.close() in the finally clause (as in try-catch-finally), 'cause otherwise, if there's an exception, it won't get closed. A finally always gets executed, exception or not.
I also dislike VB, feels so amateurish. No offense.
Always put the connection.close() in the finally clause (as in try-catch-finally), 'cause otherwise, if there's an exception, it won't get closed. and a finally always gets executed, exception or not.
I also dislike VB, feels so amateurish... no offense.
Correct me if I'm wrong (cause I usually don't use Sockets & co.), but if the Socket failed while connection, the Socked is already closed, isn't it? oO
Maybe, but the only way to truly be sure is by closing it yourself. And the only way to make sure that gets executed is in the finally clause.
EDIT: It's also good practice to always close your connections. Even if they get closed by themselves (timeout, etc.)
Maybe, but the only way to truly be sure is by closing it yourself. And the only way to make sure that gets executed is in the finally clause.
EDIT: It's also good practice to always close your connections. Even if they get closed by themselves (timeout, etc.)
I got my *** chewed on my first job for not closing my connections, boss man wondered why the app was hanging after time passed, I learned the hard way :P
hi all,
i wanted to give you a code for vb 2010 to show it the server is online or offline
first for the imports
Code:
Imports System.Net.Sockets
then under the Public Class Form1 insert this code
Code:
Dim game As New TcpClient()
Dim auth As New TcpClient()
the game dim is for the game server state and auth is for auth server state
then for the code of the status you can but it any were you want in the form load if you want it to see if the the server is off or on when the launcher is started or in a button so the player can manual see it
you will need also two labels to in your form
Try
game.Connect("gameserver ip", game server port example {4515} )
Catch ex As Exception
label1.Text = "Offline"
label1.ForeColor = Color.Red
End Try
Try
auth.Connect("authserver ip",port example {1433} )
Catch ex As Exception
label2.Text = "Offline"
label2.ForeColor = Color.Red
End Try
If game.Connected Then
label1.Text = "Online"
label1.ForeColor = Color.Green
End If
If auht.Connected Then
label2.Text = "Online"
label2.ForeColor = Color.Green
End If
and this is the link for the FULL launcher just edit the IP and PORT
download form : Screenshoots
if it's not online
i hope you like it , and if you had any problem please post in this topic or pm .
have a nice day.
What this script automatically change the status when the server is down?
because when i'm test to start and down server, a launcher doesn't automatically change status online and offline
What this script automatically change the status when the server is down?
because when i'm test to start and down server, a launcher doesn't automatically change status online and offline
just add the try code to a timer so it check it every sec
thanks for the share can anyone tell me what does mean by import "Imports System.Net.Sockets" i dont get this part . am noob with vb so am kinda clueless and dont know where to put it
can anyone guide me plz thanks for reading