Ejemplo n.º 1
0
        public bool Connect()
        {
            if (!tryconnecting && !Connected)
            {
                if (Server == null)
                {
                    tryconnecting = true;

                    Server = new GarageServer.TrafficMessageClient();

                    if (Server != null)
                    {
                        if (!DoHandShake())
                        {
                            Server        = null;
                            ServerName    = "";
                            tryconnecting = false;
                        }
                    }
                }
            }
            return(false);
        }
Ejemplo n.º 2
0
        public bool HandShake(string devicename, string devicetype, ref int deviceID, ref int serverID, ref string ServerName, GarageServer.TrafficMessageClient Server)
        {
            string result;

            try
            {
                result = Server.Handshake(1, DeviceName + "," + devicetype);
            }
            catch
            {
                Debug.WriteLine("Handshake failed (0)");
                return(false);
            }

            if (Int32.TryParse(result, out deviceID))
            {
                if (deviceID > 0)
                {
                    comID = deviceID;

                    Debug.WriteLine("Completed handshake 1");

                    result = Server.Handshake(2, comID.ToString());

                    if (result.Length > 0)
                    {
                        ServerName = result;
                        Debug.WriteLine("Completed handshake 2");

                        result = Server.Handshake(3, comID.ToString());

                        int expectedserverID;

                        if (Int32.TryParse(result, out expectedserverID))
                        {
                            if (expectedserverID > 0)
                            {
                                serverID = expectedserverID;

                                Debug.WriteLine("Completed handshake 3");

                                result = Server.Handshake(4, Program.MasterServer.comID.ToString() + "," + comID);

                                if (result == "OK")
                                {
                                    Debug.WriteLine("Completed handshake 4 - linking");
                                    MadeConnection();
                                    return(true);
                                }
                                else
                                {
                                    Debug.WriteLine("Handshake failed (4)");
                                }
                            }
                            else
                            {
                                Debug.WriteLine("Handshake failed (3)");
                            }
                        }
                    }
                    else
                    {
                        Debug.WriteLine("Handshake failed (2)");
                    }
                }
                else
                {
                    Debug.WriteLine("Handshake failed (1)");
                }
            }

            if (showhandshakefailmessage)
            {
                showhandshakefailmessage = false;
                Reporter.AddReport(4, "Handshake for '" + this.DeviceName + "' failed!");
            }
            return(false);
        }