Exemple #1
0
 private void conn_idUpdate(object sender, idUpdateEventArgs e)
 {
     int position = 0;
     string temp;
     if (this.checkedListBox1.InvokeRequired)
     {
         SetTextCallback d = new SetTextCallback(conn_idUpdate);
         this.Invoke(d, this, e);
     }
     else
     {
         if (e.theIDs != null)
         {
             checkedListBox1.Items.Clear();
             foreach (users item in e.theIDs)
             {
                 if (item.id != "\0\0\0\0\0\0\0\0\0\0")
                 {
                     position = item.id.IndexOf('\0');
                     if (position != -1)
                         temp = item.id.Substring(0, position);
                     else
                         temp = item.id;
                     if (temp != this.username)
                         if (item.online)
                             checkedListBox1.Items.Add(temp, true);
                         else
                             checkedListBox1.Items.Add(temp, false);
                 }
                 else
                     break;
             }
         }
     }
 }
Exemple #2
0
        public void Reception()
        {
            int a = 1;
            try
            {
                while (true)
                {
                    data = new byte[1024];
                    a = Form1.clientSock.Receive(data);

                    if (a != 0)
                    {
                        if (Encoding.ASCII.GetString(data, 0, 10)
                            == "!!!!!!!!!!")
                        {
                            idUpdateEventArgs h = new idUpdateEventArgs(data);
                            idUpdate(this, h);
                        }
                        else
                        {
                            receptionEventArgs k = new receptionEventArgs(data);
                            received(this, k);
                        }
                    }
                    else
                    {
                        Form1.clientSock.Shutdown(SocketShutdown.Both);
                        Form1.clientSock.Close();
                        //yek event neveshte shavad ke elam konad
                        //connection close shode
                    }
                }
            }
            catch (ArgumentNullException q)
            {
                MessageBox.Show(q.Message);
            }
            catch (SocketException w)
            {
                MessageBox.Show(w.Message);
            }
            catch (ObjectDisposedException k)
            {
                MessageBox.Show("Disconnected!!");
            }
        }