Click to See Complete Forum and Search --> : Server status help / code convert from VC++ to VC#


Huntone
January 22nd, 2010, 08:43 AM
hello all, i have some problem, need to create a small form that will show server status.
Im working in Visual Studio 2010 C# language.
I have example of code but it's in VC++, i dont know how to rewrite it in VC#

this is VC++ code:

Dim tcpC As New TcpClient
Dim tcpC2 As New TcpClient
Try
tcpC.Connect(IPServer, 7777)
txtGameServer.Text = "OnLine"
txtGameServer.ForeColor = Color.Green
Catch a As Exception
txtGameServer.Text = "OffLine"
txtGameServer.ForeColor = Color.Red
End Try
tcpC.Close()
Try
tcpC2.Connect(IPServer, 2106)
txtLoginServer.Text = "OnLine"
txtLoginServer.ForeColor = Color.Green
Catch a As Exception
txtLoginServer.Text = "OffLine"
txtLoginServer.ForeColor = Color.Red
End Try
tcpC2.Close()

i need something similair for VC#
On form there is going to be something like this:
Server status: Online (or if tcp query comes in fault it says "Offline")

How can i do that, im really a newbie :) Plz help me

mariocatch
January 22nd, 2010, 09:49 AM
that's VB, not C++ lol.. but...



TcpClient tcpC = new TcpClient();
TcpClient tcpC2 = new TcpClient();

try
{
tcpC.Connect(IPServer, 7777);
txtGameServer.Text = "OnLine";
txtGameServer.ForeColor = Color.Green;
}
catch(Exception ex)
{
}
finally
{
tcpC.Close();
}
try
{
tcpC2.Connect(IPServer, 2106);
txtLoginServer.Text = "OnLine";
txtLoginServer.ForeColor = Color.Green;
}
catch(Exception ex)
{
}
finally
{
tcpC2.Close();
}

Huntone
January 22nd, 2010, 11:46 AM
This is that part:
but it wont work, its not printing out on form is it online, on form there is Game: offline part, it should print out "Online" if this scrip works :(

//Server Status !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

private void Check()
{
TcpClient tcpC = new TcpClient();
TcpClient tcpC2 = new TcpClient();

try
{
tcpC.Connect("GSLS", 7777);
game.Text = "OnLine";
game.ForeColor = Color.Green;
}
catch (Exception ex)
{
}
finally
{
tcpC.Close();
}
try
{
tcpC2.Connect("GSLS", 2106);
login.Text = "OnLine";
login.ForeColor = Color.Green;
}
catch (Exception ex)
{
}
finally
{
tcpC2.Close();
}
}



//End Server status !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

mariocatch
January 22nd, 2010, 12:12 PM
That means your Connect() is failing... which we can't help you with the code you provided..