/// <summary> /// The start receiving from server. /// </summary> /// <param name="request"> /// The request. /// </param> /// <returns> /// The <see cref="ChromelyResponse"/>. /// </returns> private ChromelyResponse StartReceivingFromServer(ChromelyRequest request) { var clientname = request.PostData?.ToString() ?? string.Empty; mReceiverConnectionId = ConnectionNameMapper.GetConnectionId(clientname); if (!mReceiveFromServer) { mReceiveFromServer = true; SendMessagesToClient(); } return(new ChromelyResponse(request.Id) { ReadyState = (int)ReadyState.ResponseIsReady, Status = (int)System.Net.HttpStatusCode.OK, StatusText = "OK", Data = "OK" }); }
/// <summary> /// The send message. /// </summary> /// <param name="clientName"> /// The client name. /// </param> /// <param name="data"> /// The data. /// </param> private static void SendMessage(string clientName, string data) { Task.Run(() => { IntPtr outIntPtr = IntPtr.Zero; try { if (string.IsNullOrEmpty(data)) { return; } int connectionId = ConnectionNameMapper.GetConnectionId(clientName); if (connectionId == 0) { return; } if (Server == null) { return; } byte[] outputByte = Encoding.UTF8.GetBytes(data); outIntPtr = Marshal.AllocHGlobal(outputByte.Length); Marshal.Copy(outputByte, 0, outIntPtr, outputByte.Length); Server.SendWebSocketMessage(connectionId, outIntPtr, outputByte.Length); } catch (Exception exception) { Log.Error(exception); } finally { // Free the unmanaged memory. Marshal.FreeHGlobal(outIntPtr); } }); }
/// <summary> /// The start receiving from server. /// </summary> /// <param name="request"> /// The request. /// </param> /// <returns> /// The <see cref="ChromelyResponse"/>. /// </returns> private ChromelyResponse StartReceivingFromServer(ChromelyRequest request) { string clientname = request.PostData?.ToString() ?? string.Empty; this.mReceiverConnectionId = ConnectionNameMapper.GetConnectionId(clientname); if (!this.mReceiveFromServer) { this.mReceiveFromServer = true; this.SendMessagesToClient(); } ChromelyResponse response = new ChromelyResponse(request.Id); response.ReadyState = (int)ReadyState.ResponseIsReady; response.Status = (int)System.Net.HttpStatusCode.OK; response.StatusText = "OK"; response.Data = "OK"; return(response); }