Exemple #1
0
        private void GetMessage()
        {
            byte[] bytesFrom = new byte[_clientSocket.ReceiveBufferSize];

            _clientSocket.Client.Receive(bytesFrom);

            string dataFromClient = Encoding.Unicode.GetString(bytesFrom);

            lock (_previousPartialMessage)
            {
                DetectDisconnectedClient(dataFromClient);
                try
                {
                    string completeMessage = _previousPartialMessage + dataFromClient;
                    //string delimieter = MudMessageInstance.Regex;
                    //string[] sections = completeMessage.Split(new[] { delimieter }, StringSplitOptions.RemoveEmptyEntries);

                    Tuple <List <string>, string> result = MudMessageInstance.ParseRawMessage(completeMessage);
                    foreach (string message in result.Item1)
                    {
                        InQueue.Enqueue(message);
                    }
                    _previousPartialMessage = result.Item2;
                }
                catch /*(Exception ex)*/
                {
                    _previousPartialMessage += dataFromClient;
                    _previousPartialMessage  = _previousPartialMessage.Replace("\0", "");
                }
            }
        }
Exemple #2
0
        protected void GetMessageLoop()
        {
            try
            {
                while ((_clientSocket.Connected))
                {
                    //Handle message from client
                    try
                    {
                        GetMessage();
                    }
                    catch /*(Exception ex)*/
                    {
                        //if (ex.InnerException != null && ex.InnerException.Message != "A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond")
                        //{
                        //    throw;
                        //}
                        throw;
                    }
                }

                if (!_clientSocket.Connected)
                {
                    throw new Exception("Server shutdown.");
                }
            }
            catch (Exception ex)
            {
                InQueue.Enqueue("<Exception> " + ex.ToString() + " </Exception>");
                _clientSocket.Close();
            }
        }
Exemple #3
0
 public void AutoArrives(Auto auto)
 {
     Simulator.Notifier.Notify(new AutoArrivingAtFacility {
         Auto = auto
     });
     if (InQueue.Count < 50)
     {
         InQueue.Enqueue(auto);
     }
     else
     {
         Simulator.Notifier.Notify(new AutoAbandoningFacility {
             Auto = auto
         });
     }
 }
Exemple #4
0
 protected void SendMessageLoop()
 {
     try
     {
         while ((_clientSocket.Connected))
         {
             while (OutQueue.TryDequeue(out string outboundMessage))
             {
                 SendMessage(outboundMessage);
             }
             Thread.Sleep(10);
         }
     }
     catch (Exception ex)
     {
         InQueue.Enqueue(" >> " + ex.ToString());
     }
 }
Exemple #5
0
 /// <summary>
 /// Add a received packet to the queue.
 /// </summary>
 /// <param name="packet"> The packet to enqueue. </param>
 protected virtual void EnqueueReceivedPacket(Packet packet)
 {
     InQueue.Enqueue(packet);
 }