CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Jan 2010
    Posts
    4

    Server status help / code convert from VC++ to VC#

    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:
    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

  2. #2
    Join Date
    Apr 2007
    Location
    Florida
    Posts
    403

    Re: Server status help / code convert from VC++ to VC#

    that's VB, not C++ lol.. but...


    Code:
    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();
    }
    Last edited by mariocatch; January 22nd, 2010 at 10:52 AM. Reason: Adding code.

  3. #3
    Join Date
    Jan 2010
    Posts
    4

    Re: Server status help / code convert from VC++ to VC#

    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

    Code:
     //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 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

  4. #4
    Join Date
    Apr 2007
    Location
    Florida
    Posts
    403

    Re: Server status help / code convert from VC++ to VC#

    That means your Connect() is failing... which we can't help you with the code you provided..

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured