Beispiel #1
0
        /// <summary>
        ///   Called when [init].
        /// </summary>
        /// <param name = "peer">The peer.</param>
        /// <param name = "data">The data.</param>
        public void OnInit(IPhotonPeer peer, byte[] data, byte channelCount)
        {
            try
            {
                if (log.IsDebugEnabled)
                {
                    Encoding utf8Encoding = Encoding.UTF8;
                    log.DebugFormat("OnInit - {0}", utf8Encoding.GetString(data));
                }

                if (data[0] == '<' && data[21] == '>')
                {
                    byte[] bytes = peer.GetLocalPort() == 943 ? this.silverlightPolicyBytesUtf8 : this.policyBytesUtf8;

                    // in case the policy app ever serves a websocket port...
                    MessageContentType contentType = peer.GetListenerType() == ListenerType.WebSocketListener
                                                         ? MessageContentType.Text
                                                         : MessageContentType.Binary;

                    peer.Send(bytes, MessageReliablity.Reliable, 0, contentType);

                    if (log.IsDebugEnabled)
                    {
                        log.Debug("Policy sent.");
                    }
                }

                peer.DisconnectClient(); // silverlight does not disconnect by itself
            }
            catch (Exception e)
            {
                log.Error(e);
                throw;
            }
        }
 public void Application_OnOutboundConnectionEstablished(IPhotonPeer peer)
 {
     lock (this.syncRoot)
     {
         this.photonPeer = peer;
     }
     if (peer.GetListenerType() != ListenerType.WebSocketListener)
     {
         if (log.IsDebugEnabled)
         {
             log.Debug("OnOutboundConnectionEstablished: sending init request");
         }
         byte[]      data    = this.protocol.SerializeInitRequest(this.appName, Versions.TcpOutboundPeerVersion);
         SendResults results = peer.Send(data, MessageReliablity.Reliable, 0, MessageContentType.Binary);
         LogInitRequest(peer, 0, data, (SendResult)results);
     }
 }
        private void HandlePingRequest(OperationRequest operationRequest)
        {
            var operation = new PingRequest(this.Protocol, operationRequest);

            if (!operation.IsValid)
            {
                Logger.ErrorFormat("[HandlePingRequest]: Received an invalid ping request. ErrorMessage={0}", operation.GetErrorMessage());
                return;
            }

            var response = new OperationResponse(operationRequest.OperationCode,
                                                 new Dictionary <byte, object>
            {
                { /*MasterTimeStamp*/ 4, (int)(DateTime.UtcNow.Ticks / TimeSpan.TicksPerMillisecond) },
                { /*ServerTimeStamp*/ 5, operation.ServerTimeStamp }
            });

            // temporarily using the un-managed peer to suppress logging
            if (Connected)
            {
                __unmanagedPeer__.Send(Protocol.SerializeOperationResponse(response), MessageReliablity.Reliable, 0, MessageContentType.Binary);
            }
        }
Beispiel #4
0
        /// <summary>
        ///   Called when [init].
        /// </summary>
        /// <param name = "peer">The peer.</param>
        /// <param name = "data">The data.</param>
        public void OnInit(IPhotonPeer peer, byte[] data)
        {
            try
            {
                if (log.IsDebugEnabled)
                {
                    Encoding utf8Encoding = Encoding.UTF8;
                    log.DebugFormat("OnInit - {0}", utf8Encoding.GetString(data));
                }

                if (data[0] == '<' && data[21] == '>')
                {
                    byte[] bytes = peer.GetLocalPort() == 943 ? this.silverlightPolicyBytesUtf8 : this.policyBytesUtf8;
                    peer.Send(bytes, MessageReliablity.Reliable, 0);

                    if (log.IsDebugEnabled)
                    {
                        log.Debug("Policy sent.");
                    }
                }

                peer.DisconnectClient(); // silverlight does not disconnect by itself
            }
            catch (Exception e)
            {
                log.Error(e);
                throw;
            }
        }