A server communicator
Inheritance: TcpCommunicator
Esempio n. 1
0
        /// <summary>
        /// Begin the main automation loop, accepting connections and executing commands
        /// </summary>
        public virtual void BeginAutomation()
        {
            try
            {
                _communicator = new TcpServerCommunicator(TCP_PORT);
                MobileDb.Instance.Register(DeviceInfo);

                while (true)
                {
                    _communicator.Initialize();
                    MobileDb.Instance.SetAvailibility(DeviceInfo, false);
                    // Returns when the connection has been closed
                    HandleConnection();
                    MobileDb.Instance.SetAvailibility(DeviceInfo, true);
                }
            }
            catch (ThreadAbortException)
            {
                // App is shutting down, clean up
                _communicator.Close();
                MobileDb.Instance.SetAvailibility(DeviceInfo, false);
            }
        }
 /// <summary>
 /// Recieve multiple connections, each connection is passed to the callback in a new thread. Does not return.
 /// </summary>
 /// <param name="callback"></param>
 private void AcceptMultiple(ConnectionCallback callback)
 {
     while(true)
     {
         var comm = new TcpServerCommunicator(Port, AcceptClient());
         var thread = new Thread(() => callback(comm));
         thread.Start();
     }
 }