Esempio n. 1
0
        void ConnectIfNeeded()
        {
            if (sock.IsConnected)
            {
                return;
            }

            sock.BinaryDataArrived += new TSocket.RawHandler(sock_BinaryDataArrived);
            sock.XmlDataArrived    += new TSocket.DataHandler(sock_XmlDataArrived);
            sock.Disconnected      += (s) =>
            {
                if (OnError != null)
                {
                    OnError("Disconnected");
                }
            };

retry:
            Trace.WriteLine("Connecting to " + Host + ":" + Port);
            try
            {
                sock.Connect(Host, Port);
            }
            catch (Exception ex)
            {
                Trace.WriteLine(Name + " Connection Failed: " + ex.Message);
                if (OnError != null)
                {
                    OnError(ex.Message);
                }
                goto retry;
            }
        }