コード例 #1
0
        /// <summary>
        /// The on message.
        /// </summary>
        /// <param name="connectionId">
        /// The connection id.
        /// </param>
        /// <param name="data">
        /// The data.
        /// </param>
        /// <param name="dataSize">
        /// The data size.
        /// </param>
        public void OnMessage(int connectionId, IntPtr data, long dataSize)
        {
            Task.Run(() =>
            {
                IntPtr tempPtr = IntPtr.Zero;

                try
                {
                    var managedArray = new byte[dataSize];
                    Marshal.Copy(data, managedArray, 0, (int)dataSize);
                    tempPtr = Marshal.AllocHGlobal(managedArray.Length);
                    Marshal.Copy(managedArray, 0, tempPtr, managedArray.Length);

                    var requestString = Encoding.UTF8.GetString(managedArray);
                    var requestInfo   = new RequestInfo(requestString);

                    switch (requestInfo.Type)
                    {
                    case MessageType.Echo:
                        WebsocketMessageSender.Send(connectionId, requestInfo.Data);
                        break;

                    case MessageType.TargetRecepient:
                        WebsocketMessageSender.Send(requestInfo.TargetConnectionId, requestInfo.Data);
                        break;

                    case MessageType.Broadcast:
                        WebsocketMessageSender.Broadcast(connectionId, requestInfo.Data);
                        break;

                    case MessageType.ControllerAction:
                        var jsonData = JsonMapper.ToObject <JsonData>(requestString);
                        var request  = new ChromelyRequest(jsonData);
                        var response = RequestTaskRunner.Run(request);
                        WebsocketMessageSender.Send(connectionId, response);
                        break;

                    default:
                        WebsocketMessageSender.Send(connectionId, requestInfo.Data);
                        break;
                    }
                }
                catch (Exception exception)
                {
                    Log.Error(exception);
                }
                finally
                {
                    // Free the unmanaged memory.
                    Marshal.FreeHGlobal(tempPtr);
                }
            });
        }
コード例 #2
0
 /// <summary>
 /// The broadcast.
 /// </summary>
 /// <param name="connectionId">
 /// The connection id.
 /// </param>
 /// <param name="data">
 /// The data.
 /// </param>
 public void Broadcast(int connectionId, string data)
 {
     WebsocketMessageSender.Broadcast(connectionId, data);
 }
コード例 #3
0
 /// <summary>
 /// The broadcast.
 /// </summary>
 /// <param name="connectionId">
 /// The connection id.
 /// </param>
 /// <param name="response">
 /// The response.
 /// </param>
 public void Broadcast(int connectionId, ChromelyResponse response)
 {
     WebsocketMessageSender.Broadcast(connectionId, response);
 }
コード例 #4
0
 /// <summary>
 /// The broadcast.
 /// </summary>
 /// <param name="connectionId">
 /// The connection id.
 /// </param>
 /// <param name="data">
 /// The data.
 /// </param>
 /// <param name="dataSize">
 /// The data size.
 /// </param>
 public void Broadcast(int connectionId, IntPtr data, long dataSize)
 {
     WebsocketMessageSender.Broadcast(connectionId, data, dataSize);
 }