private void _sendButton_Click(object sender, EventArgs e) { var nickName = _nickName.Text; var message = _sayBox.Text; _sayBox.SelectAll(); ThreadPool.QueueUserWorkItem(x => _chatProxy.SendMessage(nickName, message)); }
static void Main(string[] args) { System.Console.Write("Nickname: "); _nickName = System.Console.ReadLine(); System.Console.WriteLine("-----------------------------------------------"); Hashtable credentials = new Hashtable(); credentials.Add("nickname", _nickName); ZyanConnection connection = null; TcpDuplexClientProtocolSetup protocol = new TcpDuplexClientProtocolSetup(true); try { connection = new ZyanConnection(Properties.Settings.Default.ServerUrl, protocol, credentials, false, true); } catch (SecurityException ex) { System.Console.WriteLine(ex.Message); System.Console.ReadLine(); return; } connection.CallInterceptors.For <IMiniChat>().Add( (IMiniChat chat, string nickname, string message) => chat.SendMessage(nickname, message), (data, nickname, message) => { if (message.Contains("f**k") || message.Contains("sex")) { System.Console.WriteLine("TEXT CONTAINS FORBIDDEN WORDS!"); data.Intercepted = true; } }); connection.CallInterceptionEnabled = true; IMiniChat chatProxy = connection.CreateProxy <IMiniChat>(); chatProxy.MessageReceived += new Action <string, string>(chatProxy_MessageReceived); string text = string.Empty; while (text.ToLower() != "quit") { text = System.Console.ReadLine(); chatProxy.SendMessage(_nickName, text); } chatProxy.MessageReceived -= new Action <string, string>(chatProxy_MessageReceived); connection.Dispose(); }