Esempio n. 1
0
        /// <summary>
        /// Destroy the static refrence and close all connections.
        /// </summary>
        /// <param name="refrenceID"></param>
        public static void DestroyStaticRefrenceById(string refrenceID)
        {
            if (!sm_StaticRefrences.ContainsKey(refrenceID))
            {
                return;
            }

            CSCom com = sm_StaticRefrences[refrenceID];

            sm_StaticRefrences.Remove(refrenceID);

            // send the destroy command.
            if (com.IsAlive)
            {
                com.Send(NPMessage.FromValue(null, NPMessageType.Destroy, "C# static refrence destoryed."));
                com.Stop();
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Sends a message and waits for response if needed.
        /// </summary>
        /// <param name="msg">The message to send</param>
        /// <param name="requireResponse">If true a response will be required from the other party. Synchronius action.</param>
        /// <param name="toWebsocket">If null then broadcase (as a server, this would mean sending to all clients)</param>
        /// <returns>The response if required, otherwise null.</returns>
        public NPMessage Send(NPMessage msg, bool requireResponse = false, string toWebsocket = null)
        {
            // empty string is null in this case.
            if (toWebsocket != null && toWebsocket.Length == 0)
            {
                toWebsocket = null;
            }

            NPMessage response = null;

            if (requireResponse)
            {
                Pipe.Send(msg, toWebsocket, (rsp) =>
                {
                    response = rsp;
                });
            }
            else
            {
                Pipe.Send(msg, toWebsocket);
            }

            return(response);
        }
Esempio n. 3
0
 private void SendErrorMessage(string id, Exception ex)
 {
     MessageRecived(this,
                    new WebsocketPipe <NPMessage> .MessageEventArgs(NPMessage.FromValue(ex.ToString(), NPMessageType.Error, ex.ToString()), false, id));
 }