Ejemplo n.º 1
0
 private void Radio_Thread_Elapsed(object sender, ElapsedEventArgs e)
 {
     try
     {
         lis.Radio_Send_Message(select_device_id, WIFI_Protocol.Construct_Data_Packet(new TransData_Struct(Protocol_Keyword.State_Binding, new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 }, gb2312.GetBytes(listbox_value))));
     }
     catch (Exception e2)
     {
     }
 }
Ejemplo n.º 2
0
        private void Button_Click_1(object sender, RoutedEventArgs e)
        {
            byte[]   aaa = new byte[1024 * 32];
            byte[][] bbb = new byte[Protocol_Keyword_Function.Dic_Protocol.Count][];
            for (int i = 0; i < bbb.Length; i++)
            {
                bbb[i] = Encoding.ASCII.GetBytes(Dic_Protocol[(Protocol_Keyword)i].State_string);
            }
            Random re = new Random();

            for (int i = 0; i < 10000; i++)
            {
                bbb[i % bbb.Length].CopyTo(aaa, re.Next(0, aaa.Length - bbb[i % bbb.Length].Length));
            }
            List <int>[] ddd = WIFI_Protocol.Search_ByteArray_String(ref aaa, ref bbb);

            MessageBox.Show(ddd[0].Count.ToString());
        }
Ejemplo n.º 3
0
 private void Radio_ALLDevice_NickName_Thread_Elapsed(object sender, ElapsedEventArgs e)
 {
     if (RadioQueue.Count > 0)
     {
         for (int i = 0; i < ListeningThread.DeviceList_Thread.Count; i++)
         {
             string rfID       = ListeningThread.DeviceList_Thread[i].Device_Recv_Struct.Device_ID;
             string rfNickname = ListeningThread.DeviceList_Thread[i].Device_Recv_Struct.Bind_User;
             if (RadioQueue[0].id == rfID)
             {
                 if (RadioQueue[0].nickname == rfNickname)
                 {
                     RadioQueue.RemoveAt(0);
                     return;
                 }
                 else
                 {
                     lis.Radio_Send_Message(RadioQueue[0].id, WIFI_Protocol.Construct_Data_Packet(new TransData_Struct(Protocol_Keyword.State_Binding, new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 }, gb2312.GetBytes(RadioQueue[0].nickname))));
                 }
             }
         }
     }
     //throw new NotImplementedException();
 }
Ejemplo n.º 4
0
        private void Listen_Function()
        {
            server_thread = true;
            while (server_thread)
            {
                byte[] temporary     = new byte[1024 * 10];
                int    temporary_len = 0;
                int    sendTimes     = 0;
                string New_DeviceID;
                List <Protocol_Keyword_Function.TransData_Struct> list = new List <Protocol_Keyword_Function.TransData_Struct>();
                Socket socket;
                try
                {
                    socket = Listen_Socket.Accept();
                }
                catch (Exception e)
                {
                    error_message.Add(e.Message);
                    continue;
                }
                socket.ReceiveTimeout = 20000;
                // Thread.Sleep(500);
                while (true)
                {
                    int recv_len = 0;
                    try
                    {
                        byte[] send = WIFI_Protocol.Construct_Data_Packet(new Protocol_Keyword_Function.TransData_Struct(Protocol_Keyword_Function.Protocol_Keyword.State_DeviceInfo, new byte[] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, new byte[] { }));
                        sendTimes++;
                        socket.Send(send);

                        recv_len = socket.Receive(temporary, temporary_len, 1024 * 10 - temporary_len, SocketFlags.None);
                    }
                    catch (Exception e)
                    {
                        error_message.Add(e.Message);
                        if (sendTimes > 5)
                        {
                            socket.Close();
                            break;
                        }
                        continue;
                    }
                    if (recv_len > 0)
                    {
                        WIFI_Protocol.AnalysisRawData(ref temporary, ref list);
                        if (list.Count > 0)
                        {
                            New_DeviceID = Encoding.ASCII.GetString(list[0].Device_ID);

                            int i;
                            for (i = 0; i < DeviceList_Thread.Count; i++)
                            {
                                if (DeviceList_Thread[i].Device_Recv_Struct.Device_ID == New_DeviceID)
                                {
                                    DeviceList_Thread[i].Ser = socket;
                                    break;
                                }
                            }
                            if (i == DeviceList_Thread.Count)
                            {
                                ServiceThread server = new ServiceThread(_wavfs, _wavfilesec, _wavfiledir, socket);
                                string        str    = socket.RemoteEndPoint.ToString();
                                int           con    = 0;
                                for (int j = 0; j < str.Length; j++)
                                {
                                    if (str[j] == ':')
                                    {
                                        con = j;
                                    }
                                }
                                string port = str.Substring(con + 1);
                                string ip   = str.Substring(0, con);
                                server.Device_Recv_Struct.Device_ID = New_DeviceID;
                                server.ipaddress = ip;
                                server.port      = port;
                                DeviceList_Thread.Add(server);
                            }
                            break;
                        }
                        else
                        {
                            temporary_len += recv_len;
                        }
                    }
                    else
                    {
                        continue;
                    }
                }
            }
        }