Ejemplo n.º 1
0
        protected bool sendHandshake()
        {
            BayeuxClientState bayeuxClientState = this.bayeuxClientState;

            if (isHandshaking(bayeuxClientState))
            {
                IMutableMessage message = newMessage();
                if (bayeuxClientState.handshakeFields != null)
                {
                    foreach (KeyValuePair <String, Object> kvp in bayeuxClientState.handshakeFields)
                    {
                        message.Add(kvp.Key, kvp.Value);
                    }
                }

                message.Channel = Channel_Fields.META_HANDSHAKE;
                message[Message_Fields.SUPPORTED_CONNECTION_TYPES_FIELD] = AllowedTransports;
                message[Message_Fields.VERSION_FIELD] = BayeuxClient.BAYEUX_VERSION;
                if (message.Id == null)
                {
                    message.Id = newMessageId();
                }

                //Console.WriteLine("Handshaking with extra fields {0}, transport {1}", Print.Dictionary(bayeuxClientState.handshakeFields), Print.Dictionary(bayeuxClientState.transport as IDictionary<String, Object>));
                bayeuxClientState.send(handshakeListener, message);
                return(true);
            }
            return(false);
        }
Ejemplo n.º 2
0
        protected bool sendConnect()
        {
            LogHelper.Log($"BayeauxClient: sendConnect()...");

            BayeuxClientState bayeuxClientState = this.bayeuxClientState;

            if (isHandshook(bayeuxClientState))
            {
                IMutableMessage message = newMessage();
                message.Channel = Channel_Fields.META_CONNECT;
                message[Message_Fields.CONNECTION_TYPE_FIELD] = bayeuxClientState.transport.Name;
                if (bayeuxClientState.type == State.CONNECTING || bayeuxClientState.type == State.UNCONNECTED)
                {
                    // First connect after handshake or after failure, add advice
                    message.getAdvice(true)["timeout"] = 0;
                }
                bayeuxClientState.send(connectListener, message);
                LogHelper.Log($"BayeauxClient: sendConnect() returning true.");
                return(true);
            }

            LogHelper.Log($"BayeauxClient: sendConnect() returning false.");

            return(false);
        }
Ejemplo n.º 3
0
        protected bool sendMessages(IList <IMutableMessage> messages)
        {
            BayeuxClientState bayeuxClientState = this.bayeuxClientState;

            if (bayeuxClientState.type == State.CONNECTING || isConnected(bayeuxClientState))
            {
                bayeuxClientState.send(publishListener, messages);
                return(true);
            }
            else
            {
                failMessages(null, ObjectConverter.ToListOfIMessage(messages));
                return(false);
            }
        }