Exemple #1
0
        public void CloseClient(Client client)
        {
            lock(_sync)
            _clients.Remove(client);

             client.Dispose();
        }
Exemple #2
0
        public void DispatchGlow(GlowContainer glow, Provider.Client source)
        {
            var visitor = new ConsumerToProviderTranslator(_endPoints);
            var newGlow = glow.Accept(visitor, null).FirstOrDefault();

            if (newGlow != null)
            {
                if (visitor.EndPointNumber != null)
                {
                    // message to provider
                    var endPoint = (from ep in _endPoints
                                    where ep.LocalNumber == visitor.EndPointNumber.Value
                                    select ep)
                                   .FirstOrDefault();

                    if (endPoint.State == Consumer.GlowEndPointState.Connected ||
                        endPoint.State == Consumer.GlowEndPointState.ProtocolProbing)
                    {
                        endPoint.Write(newGlow);
                    }
                    else
                    {
                        // if endpoint is offline, and a dir command has been issued
                        // on the endpoint node (top-level node) -> send empty top-level node
                        if (newGlow is GlowRootElementCollection)
                        {
                            var command = newGlow.FirstOrDefault() as GlowCommand;

                            if (command != null &&
                                command.Number == GlowCommandType.GetDirectory)
                            {
                                var root = GlowRootElementCollection.CreateRoot();
                                root.Insert(new GlowNode(endPoint.LocalNumber));
                                source.Write(root);
                            }
                        }
                    }
                }
                else
                {
                    // message to proxy - usually command at root level
                    source.Write(newGlow);
                }
            }
        }
Exemple #3
0
        void AcceptCallback(IAsyncResult result)
        {
            var listener = (TcpListener)result.AsyncState;

             try
             {
            var socket = listener.EndAcceptSocket(result);
            var client = new Client(this, socket, MaxPackageLength, Proxy);

            lock(_sync)
               _clients.Add(client);

            listener.BeginAcceptSocket(AcceptCallback, listener);
            socket.BeginReceive(_buffer, 0, _buffer.Length, SocketFlags.None, ReceiveCallback, client);
             }
             catch(SocketException ex)
             {
            Console.WriteLine("Accept error: {0}", ex);
             }
             catch(ObjectDisposedException)
             {
             }
        }