//This is called when a message is received (before any events are called) private void OnBroadcastMessage(IAsyncResult res) { byte[] received = client.EndReceive(res, ref remoteEP); // Begin receiving A$AP client.BeginReceive(new AsyncCallback(OnBroadcastMessage), null); //Process the message if (!remoteEP.Address.Equals(localEP.Address)) // message is from someone else { NewBroadcastEventArgs args = new NewBroadcastEventArgs(); args.message = new RemoteMessage(received); switch (args.message.Event) { case Event.Join: OnJoin(args); break; case Event.Discovery: OnDiscovery(args); break; case Event.Leave: OnLeave(args); break; case Event.Message: OnMessage(args); break; } } }
public void OnBroadcastLeave(object sender, NewBroadcastEventArgs e) => Dispatcher.BeginInvoke(new Action(() => Broadcast_Leave(new RemoteClient(e.message.Contents)) ));
public void OnBroadcastMessage(object sender, NewBroadcastEventArgs e) => Dispatcher.BeginInvoke(new Action(() => Broadcast_Message(e.message) ));
protected virtual void OnMessage(NewBroadcastEventArgs e) { EventHandler <NewBroadcastEventArgs> handler = Message; handler?.Invoke(this, e); }
protected virtual void OnDiscovery(NewBroadcastEventArgs e) { EventHandler <NewBroadcastEventArgs> handler = Discovery; handler?.Invoke(this, e); }
// EventThing protected virtual void OnJoin(NewBroadcastEventArgs e) { EventHandler <NewBroadcastEventArgs> handler = Join; handler?.Invoke(this, e); }