A server communicator
Inheritance: TcpCommunicator
Ejemplo 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);
            }
        }
Ejemplo n.º 2
0
 /// <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();
     }
 }