BlottoBeats.Library.Networking.BBServerConnection.Test C# (CSharp) Method

Test() public method

Tests the server to see if the connection is valid
public Test ( ) : bool
return bool
        public bool Test()
        {
            bool result = false;

            try
            {
                using (TcpClient client = new TcpClient())
                {
                    client.Connect(serverEndPoint);
                    NetworkStream networkStream = client.GetStream();

                    result = Message.Test(networkStream);
                }
            }
            catch (SocketException) { return false; }

            return result;
        }

Usage Example

Ejemplo n.º 1
0
        private void testNewIP(string newIP)
        {
            BBServerConnection newServer = new BBServerConnection(newIP, 3000);

            if (newServer.Test())
            {
                form.server.ip = this.ip.Text;
                Properties.Settings.Default.lastIP = form.server.ip;
            }
            else MessageBox.Show("Server is not connected. Try again later", "Change IP failed");
        }