Ejemplo n.º 1
0
        public Server()
        {
            this._settings = new Settings();
            this._items = new Items();
            this.clients = new ClientList(ref this._settings, ref this._items);
            this._listener = new Listener(ref this._settings, ref this.clients);
            this.iu = new InterfaceUpdater(ref this._settings, ref this._listener, ref this.clients, ref _items);

            this._items.Bind(ref this.clients);
        }
        public InterfaceUpdater(ref Settings _settings, ref Listener _listener, ref ClientList clients, ref Items auctionItems)
        {
            this.runnig = false;
            this.updateing = false;

            this._settings = _settings;
            this._listener = _listener;
            this.clients = clients;
            this.auctionItems = auctionItems;

            this.task = new Thread(new ThreadStart(Task));
            this.task.Name = THREAD_NAME;

            Console.Title = CONSOLE_TITLE + " - " + this._settings.ServerIP;
        }
Ejemplo n.º 3
0
        public Listener(ref Settings _settings, ref ClientList _clientList)
        {
            this.runnig = false;
            this.closed = false;

            this.idConter = 0;

            this._clientList = _clientList;

            // Socket setup
            this._socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
            this._socket.Bind(_settings.ServerIP);
            this._socket.Listen(_settings.ServerQueueSize);

            // Worker thread setup
            this._task = new Thread(new ThreadStart(Task));
            this._task.IsBackground = false;
            this._task.Name = THREAD_NAME;
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Прослушивание входящих соединений
        /// </summary>
        private void ListeningIncomingConnetions()
        {
            TcpClient incomingConnection;

            while (!listenToken.Token.IsCancellationRequested)
            {
                Thread.Sleep(50);
                if (!tcpListener.Pending())
                {
                    continue;                         // Попытка соединения
                }
                incomingConnection = tcpListener.AcceptTcpClient();

                string          clientName = ReceiveMessage(incomingConnection); // Получаем имя клиента и добавляем его в список
                ConnectedClient client     = new ConnectedClient(incomingConnection, clientName, new CancellationTokenSource());
                dispatcher.BeginInvoke(new Action(() => ClientList.Add(client)));

                Task.Run(() => ClientMessaging(client));
                AddToLog(this, $"{client.Login} successful connected");
            }
        }
Ejemplo n.º 5
0
 public void Bind(ref ClientList clients)
 {
     this.clients = clients;
 }