private void MessageCallBack(IAsyncResult result) { byte[] receivedData = client.EndReceive(result, ref remoteEP); string message = Name + ": " + Encoding.ASCII.GetString(receivedData); NewMessageEventArgs args = new NewMessageEventArgs(); args.message = message; NewMessage(this, args); client.BeginReceive(new AsyncCallback(MessageCallBack), null); }
protected virtual void OnNewMessage(NewMessageEventArgs e) { EventHandler <NewMessageEventArgs> handler = NewMessage; handler?.Invoke(this, e); }
private static void Client_NewMessage(object sender, NewMessageEventArgs e) { Console.WriteLine(e.message); }