Ejemplo n.º 1
0
        public void Send(HttpContact contact)
        {
            string o;
            if(_sendQueue.TryDequeue(out o) && o != null)
            {
                contact.GetResponse().SetContent(o);
                contact.GetChannel().SendMessage(contact.GetResponse());
                return;
            }

            _liveContact = contact;
        }
Ejemplo n.º 2
0
        public void Handshake(HttpContact contact, string[] args)
        {
            _clientLock.EnterWriteLock();
            var client = CreateKey(new Client(contact, this));
            _clientLock.ExitWriteLock();

            if (client == null)
            {
                contact.GetResponse().Status = 503;
                return;
            }

            contact.GetResponse().ContentType = "text/plain";
            contact.GetResponse().SetContent(client.Key + ":20:15:websocket,xhr-polling");//flashsocket,htmlfile,jsonp-polling
        }
Ejemplo n.º 3
0
        public void Handle(IChannel channel, Request request)
        {
            var contact = new HttpContact(channel, request, new Response {Protocol = request.GetProtocol()});
            if(contact.GetRequest().GetProtocol() == "HTTP/1.1")
                contact.GetResponse().Protocol = "1.1";

            try
            {
                _action(contact, _rx.Split(request.GetPath()));
            }
            catch (Exception e)
            {
                contact.GetResponse().Status = 500;
                contact.GetResponse().SetContent(e.ToString());
            }

            if (contact.IsAutoSendResponse)
                channel.SendMessage(contact.GetResponse());
        }
Ejemplo n.º 4
0
        public void XhrPolling(HttpContact contact, string[] args)
        {
            if (args.Length < 3)
                return;
            _clientLock.EnterReadLock();
            var client = GetClient(args[1]);
            _clientLock.ExitReadLock();
            if (client == null)
                return;

            if (contact.GetChannel().ToString().Substring(0, contact.GetChannel().ToString().IndexOf(":", StringComparison.Ordinal))
                != client.GetChannel().ToString().Substring(0, client.GetChannel().ToString().IndexOf(":", StringComparison.Ordinal)))
                return;

            if(!(client.GetChannel() is XhrChannel))
                client.Connected(new XhrChannel(contact.GetChannel().ToString().Substring(0, contact.GetChannel().ToString().IndexOf(":", StringComparison.Ordinal))));

            var channel = client.GetChannel() as XhrChannel;
            contact.GetResponse().ContentType = "text/plain";
            if (contact.GetRequest().GetMethod() == "GET")
            {
                channel.Send(contact);
                contact.IsAutoSendResponse = false;
            }
            else
            {
                //POST일 경우 클라 -> 서버
                channel.Receive(contact.GetRequest().GetLowPostData());
                contact.GetResponse().SetContent("1");
            }
        }