Example #1
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");
            }
        }
Example #2
0
 public Client(HttpContact contact, ISocketIO socketIO)
 {
     _socketIO = socketIO;
     _channel = contact.GetChannel();
     _endPoint = contact.GetRequest().GetPath();
     _endPoint = _endPoint.Substring(0, _endPoint.Length - 3);
 }
Example #3
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;
        }
Example #4
0
        public void JsonpPolling(HttpContact contact, string[] args)
        {
            if (args.Length < 3)
                return;
            _clientLock.EnterReadLock();
            var client = GetClient(args[1]);
            _clientLock.ExitReadLock();

            //contact.GetResponse().GetHeader().AppendLine("Access-Control-Allow-Origin: *");
            //contact.GetResponse().GetHeader().AppendLine("Access-Control-Allow-Credentials: true");
            //response.SetContent("0::/socket.io");
        }
Example #5
0
        public void SendMessage(dynamic message)
        {
            _sendQueue.Enqueue(message);

            lock (this)
            {
                if (_liveContact == null) return;

                var contact = _liveContact;
                _liveContact = null;
                Send(contact);
            }
        }
Example #6
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
        }
        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());
        }