Esempio n. 1
0
        public void Process()
        {
            try
            {
                _stream = _client.GetStream();
                string Imei = GetMessage();
                byte[] msg  = new byte[] { 1 };
                _server.SendMessage(msg, this.Id);

                string Message = GetMessage();
                if (Message != null)
                {
                    _message = new Message()
                    {
                        Date = DateTime.Now.ToString("HH:mm:ss"), Imei = Imei, GetMessage = Message
                    };
                    db.Messages.Add(_message);
                    db.SaveChanges();
                }

                msg = new byte[] { 2 };
                _server.SendMessage(msg, this.Id);

                Close();
            }
            catch (Exception ex)
            {
                _log.Write(ex.Message);
            }
            finally
            {
                _server.RemoveConnection(this.Id);
            }
        }
Esempio n. 2
0
        public void Start()
        {
            try
            {
                _listener.Start();
                _log.Write("server to start");

                while (true)
                {
                    _client      = _listener.AcceptTcpClient();
                    _clientLogic = new ClientLogic(_client, this);
                    _thread      = new Thread(new ThreadStart(_clientLogic.Process));
                    _thread.Start();
                }
            }
            catch (Exception ex)
            {
                _log.Write(ex.Message);
            }
        }
Esempio n. 3
0
 public void ServerListener()
 {
     try
     {
         _server       = new ServerLogic("0.0.0.0", 4000);
         _listenThread = new Thread(new ThreadStart(_server.Start));
         _listenThread.Start();
     }
     catch (Exception ex)
     {
         _server.Stop();
         _log.Write(ex.Message);
     }
 }