예제 #1
0
 public void fillMessageListView(string a, string b, string c, string d)
 {
     try
     {
         if (listviewMessages.Items.Count > 500)
         {
             listviewMessages.Items.Clear();
         }
         string[]     arr = { a, b, c, d };
         ListViewItem itm = new ListViewItem(arr);
         this.listviewMessages.Items.Add(itm);
     }
     catch (Exception e)
     {
         LogIslemleri.LogYaz("raised a exception while filling into listview.");
     }
 }
예제 #2
0
        private static void WaitClientMessage(object x)
        {
            try
            {
                ClientObject  tmpClientObject = (ClientObject)x;
                NetworkStream stream          = tmpClientObject.getNetworkStream();

                string ipadress = tmpClientObject.getClientIPAddress();

                if (bannedClientIPs != null && bannedClientIPs.Contains(ipadress)) //engellenen ip adreslerini reddetme işlemi
                {
                    tmpClientObject.block();
                    return;
                }

                int i = 0;
                //enter to an infinite cycle to be able to handle every change in stream
                while (true)
                {
                    while (!stream.DataAvailable)
                    {
                        if (bannedClientIPs != null && bannedClientIPs.Contains(ipadress))
                        {
                            tmpClientObject.unSubscribe();
                            tmpClientObject.block();
                            return;
                        }

                        Thread.Sleep(10);
                    }

                    Byte[] bytes = new Byte[tmpClientObject.getDataAmount()];


                    if (bytes.Count() == 0)
                    {
                        continue;
                    }
                    stream.Read(bytes, 0, bytes.Length);

                    //translate bytes of request to string
                    String data = Encoding.UTF8.GetString(bytes);

                    if (new System.Text.RegularExpressions.Regex("^GET").IsMatch(data))
                    {
                        const string eol = "\r\n"; // HTTP/1.1 defines the sequence CR LF as the end-of-line marker

                        Byte[] response = Encoding.UTF8.GetBytes("HTTP/1.1 101 Switching Protocols" + eol
                                                                 + "Connection: Upgrade" + eol
                                                                 + "Upgrade: websocket" + eol
                                                                 + "Sec-WebSocket-Accept: " + Convert.ToBase64String(
                                                                     System.Security.Cryptography.SHA1.Create().ComputeHash(
                                                                         Encoding.UTF8.GetBytes(
                                                                             new System.Text.RegularExpressions.Regex("Sec-WebSocket-Key: (.*)").Match(data).Groups[1].Value.Trim() + "258EAFA5-E914-47DA-95CA-C5AB0DC85B11"
                                                                             )
                                                                         )
                                                                     ) + eol
                                                                 + eol);

                        stream.Write(response, 0, response.Length);
                        tmpClientObject.subscribe();
                        webSocketUI.Invoke(new updateConnectedClientBoxDelegate(webSocketUI.updateConnectedClientBox));
                        Thread.Sleep(10);
                    }
                    else
                    {
                        tmpClientObject.unSubscribe();
                        webSocketUI.Invoke(new updateConnectedClientBoxDelegate(webSocketUI.updateConnectedClientBox));
                        Thread.Sleep(10);
                        break;
                    }
                }
            }
            catch (ThreadAbortException tae)
            {
                LogIslemleri.LogYaz(" WaitClientMessage thread içerisinde sorun oluştu ");
            }
        }