コード例 #1
0
        public void Insercao()
        {
            Thread t = new Thread(() =>
            {
                while (true)
                {
                    var texto = "Mi//" + RandomString(random.Next(1, 127 - 4));
                    // Initialise a packet object to store the data to be sent
                    Packet sendData = new Packet();
                    sendData.ReadData.Add("ChatName", Global.name);
                    sendData.ReadData.Add("ChatDataIdentifier", DataIdentifier.Message);
                    sendData.ReadData.Add("ChatMessage", texto);

                    // Get packet as byte array
                    IPEndPoint client = IpData.CreateIPEndPoint(_serverIP);
                    // Initialise the EndPoint for the client
                    Global.epClient = (EndPoint)client;
                    byte[] byteData = sendData.GetDataStream();
                    Global.clientSocket.BeginSendTo(byteData, 0, byteData.Length, SocketFlags.None, Global.epClient, new AsyncCallback(this.Client.SendData), Global.epClient);
                    Thread.Sleep(random.Next(100, 400));
                }
            });

            t.IsBackground = true;
            t.Start();
        }
コード例 #2
0
        public void Busca()
        {
            Thread t = new Thread(() =>
            {
                while (true)
                {
                    // Initialise a packet object to store the data to be sent
                    Packet sendData = new Packet();
                    sendData.ReadData.Add("ChatName", Global.name);
                    sendData.ReadData.Add("ChatDataIdentifier", DataIdentifier.SiteIndex);
                    sendData.ReadData.Add("Index", random.Next(0, 1000000000));
                    // Get packet as byte array
                    IPEndPoint client = IpData.CreateIPEndPoint(_serverIP);
                    // Initialise the EndPoint for the client
                    Global.epClient = (EndPoint)client;
                    byte[] byteData = sendData.GetDataStream();
                    Global.clientSocket.BeginSendTo(byteData, 0, byteData.Length, SocketFlags.None, Global.epClient, new AsyncCallback(this.Client.SendData), Global.epClient);
                    Thread.Sleep(random.Next(200, 800));
                }
            });

            t.IsBackground = true;
            t.Start();
        }