Exemplo n.º 1
0
            public void receiving()
            {
                int a = 0;

                for (; ; )
                {
                    byte[] message = new byte[1024];

                    a = sock.Receive(message);
                    if (a == 0)
                    {
                        //MessageBox.Show("The Client was Disconnected!");
                        //in event methode send message ra farakhani mikonad
                        //ke an method sockete morede nazar ra az socketArray
                        //hazf mikonad ve eventi ijad mikonad ke liste user haye
                        //online update shavad
                        messageReceptionEventArgs f = new messageReceptionEventArgs(message, true, sock);
                        messageReceived(this, f);
                        //
                        disconnectionEventArgs po = new disconnectionEventArgs(sock);
                        Disconnection(this, po);

                        break;
                    }
                    else
                    {
                        messageReceptionEventArgs k = new messageReceptionEventArgs(message, false, sock);
                        messageReceived(this, k);
                    }
                }
            }
Exemplo n.º 2
0
        private void rt_Disconnection(object sender, disconnectionEventArgs e)
        {
            int i = 0, n = 0, eachItem = 10;
            Socket temp;
            string temp1;
            byte[] x = new byte[1024];
            //alamati ke be tarafe moghabel neshan midahad
            //ke in message havie ID ha ast
            Encoding.ASCII.GetBytes("!!!!!!!!!!", 0, 10, x, 0);
            this.fetchIDs();
            foreach (string item in IDs)
                if (item != null)
                {
                    temp1 = item.TrimEnd();
                    n = eachItem;
                    Encoding.ASCII.GetBytes(temp1, 0, temp1.Length, x, n);
                    n += temp1.Length;

                    i = 10 - (temp1.Length);
                    for (int w = 0; w < i; ++w)
                    {
                        Encoding.ASCII.GetBytes("\0", 0, 1, x, n);
                        ++n;
                    }

                    if (isOnline(temp1))
                    {
                        Encoding.ASCII.GetBytes("$", 0, 1, x, n);
                    }
                    else
                    {
                        Encoding.ASCII.GetBytes("%", 0, 1, x, n);
                    }

                    eachItem += 11;
                }
            foreach (DictionaryEntry item in socketArray)
            {
                temp = (Socket)item.Value;
                temp.Send(x);
            }
        }