Spinach.AsynchronousClient.SendMultiClient C# (CSharp) Method

SendMultiClient() public method

public SendMultiClient ( ) : void
return void
        public void SendMultiClient()
        {
            try
            {
                if (table.Count > 1)
                {
                    int count = 0;
                    resetEvent = new ManualResetEvent[table.Count - 1];
                    foreach (string IPPort in table.Keys)
                    {
                        if (IPPort != selfip)
                        {
                            resetEvent[count] = new ManualResetEvent(false);
                            Peer mPeer = (Peer)table[IPPort];
                            string ip = mPeer.mIP;
                            int port = Int32.Parse(mPeer.mPort);
                            BroadcastClient temp = new BroadcastClient(ip, port, MultiMsg);
                            ThreadPool.QueueUserWorkItem(new WaitCallback(temp.StartClient), (object)count);
                            count++;
                        }
                    }
                    foreach (WaitHandle w in resetEvent)
                    {
                        w.WaitOne();
                    }
                }
            }
            catch (Exception e)
            {
                //System.Windows.Forms.MessageBox.Show(e.Message, "Failed to send to multiple client.");
                Console.WriteLine(e.Message);
            }
        }
        public void SendMultiClientChat()

Usage Example

Example #1
0
        public void sourceCodeChanged(string lno, string inputs, string mod, string uname)
        {
            Thread.Sleep(50);
            lock (this)
            {
                if (permissions.Count > 1)
                {
                    string s = inputs.Replace('<', '%');
                    s = s.Replace('>', '@');
                    string codechange = "<SourceChange>" + "<Pid>" + Pid.ToString() + "</Pid>" + "<lno>" + lno.ToString() + "</lno>" + "<s>" + s.ToString() + "</s>" + "<mod>" + mod + "</mod>" + "<uname>" + uname + "</uname>" + "</SourceChange>";
                    AsynchronousSocketListener msocket = conn.getSocket();
                    string myIP = msocket.GetIP();
                    string myPort = msocket.GetPort();

                    List<string> endPoints = Peers();
                    Hashtable temp = conn.GetIPtoPeer();
                    Hashtable tempToSend = new Hashtable();

                    foreach (DictionaryEntry item in temp)
                    {
                        if (endPoints.Contains(item.Key.ToString()))
                        {
                            tempToSend.Add(item.Key, item.Value);
                        }
                    }

                    AsynchronousClient client = new AsynchronousClient();
                    client.SetMultiMsg(tempToSend, codechange, myIP + ":" + myPort);
                    //Thread t = new Thread(new ThreadStart(client.SendMultiClient));
                    try
                    {
                        client.SendMultiClient();
                    }
                    catch (Exception e)
                    { Console.WriteLine(e.ToString()); }
                    
                }
            }
        }