Note that there are some explanatory texts on larger screens.

plurals
  1. POConsumer Publisher model for Socket communication
    text
    copied!<p>I am implementing publisher consumer model for UDP socket communication. In that application the consumers will create the UDP socket while subscribing the events.So each consumer will have different IP address and port for data sending. And process of subscribing to events is dynamic means we can add subscribers run time. In my application the publisher invokes the event when after some interval of time. Suppose in my application currently I have 5 subscribers so after invoking the method by publisher, this data should be sent to 5 different subscribers using their IP and Port. As I am having single method of sending data in subscribers, I am not getting how to send data to different IP and port simultaneously? How to maintain the states of event handlers? Please help me.</p> <p>Here I am adding the sample code.</p> <pre><code>public class Program { public static EventHandler&lt;ListEventArgs&gt; DataSending; static void Main(string[] args) { Class1.CreateNewEvent(); Class1.CreateNewEvent(); Class1.CreateNewEvent(); Class1.CreateNewEvent(); Class1.CreateNewEvent(); OnDataSending("Hello2"); Console.ReadLine(); } static void OnDataSending(object data) { if (DataSending != null) { List&lt;string&gt; ss = new List&lt;string&gt;(); ss.Add(IPADDRESS); ss.Add(PORT); DataSending(data,new ListEventArgs(ss)); } } } public static class Class1 { public static void CreateNewEvent() { Program.DataSending += new EventHandler&lt;ListEventArgs&gt;(newEvent); } static void newEvent(object o, ListEventArgs e) { //Code for socket creation and sending data } } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload