private void buttonStart_Click(object sender, EventArgs e)
        {
            //Проверка на пустоту введеных данных
            if (!string.IsNullOrEmpty(textBoxIP.Text) && !string.IsNullOrEmpty(textBoxPort.Text) && !string.IsNullOrEmpty(textBoxMessages.Text))
            {
                Ip = textBoxIP.Text;
                //проверка что порт введен коректно
                try
                {
                    Port = Convert.ToInt32(textBoxPort.Text);
                }
                catch (FormatException ex)
                {
                    MessageBox.Show(ex.Message, "MyError 01", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }

                serverUDP = new ServerUDP();
                //если с портом все ок
                if (Port != 0 && Ip != " ")
                {
                    serverUDP.SendMessages(Ip, Port, textBoxMessages.Text);

                    textBoxInformation.Text += "Сообщение отправлено" + Environment.NewLine;
                }
                else
                {
                    MessageBox.Show("Что то пошло не так с входящими данными", "MyError02", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
            else
            {
                MessageBox.Show("Ошибка заполните все поля", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Exemplo n.º 2
0
 public TestNet(string key)
 {
     this.key = key;
     if (key == "TCP")
     {
         serverTCP = new ServerTCP();
         clientTCP = new ClientTCP();
     }
     else if (key == "UDP")
     {
         clientUDP = new ClientUDP();
         ServerUDP = new ServerUDP();
     }
 }
Exemplo n.º 3
0
        public static void startUDP(int qtdClients)
        {
            var    sUDP      = new ServerUDP();
            Thread serverUdp = new Thread(sUDP.ReceiveSend);

            serverUdp.Start();
            Thread[]  clients = new Thread[qtdClients];
            Stopwatch watch   = Stopwatch.StartNew();

            for (var i = 0; i < qtdClients; i++)
            {
                var cUDP = new ProgramaClienteTCP();
                clients[i] = new Thread(cUDP.Main);
                clients[i].Start();
            }

            for (var i = 0; i < qtdClients; i++)
            {
                if (i == 0)
                {
                    watch.Stop();
                }
                clients[i].Join();
            }
            executions.Add(watch.ElapsedMilliseconds);
            amountOfTimeEllapsed += watch.ElapsedMilliseconds;
            Console.WriteLine("Total time ellapsed: {0} in milliseconds", amountOfTimeEllapsed);
            var mediaOfTimeReq = (double)amountOfTimeEllapsed / (double)10000;

            Console.WriteLine("Media of time by requisition: {0} in milliseconds", mediaOfTimeReq);
            double deviation = 0;

            foreach (var i in executions)
            {
                deviation += Math.Pow((i - mediaOfTimeReq), 2);
            }
            deviation /= (double)10000;
            deviation  = Math.Sqrt(deviation);
            Console.WriteLine("Deviation: {0}", deviation);
        }
Exemplo n.º 4
0
 private void btnReceive_Click(object sender, EventArgs e)
 {
     txtReport.AppendText(ServerUDP.ReceiveUdp(1901));
 }
Exemplo n.º 5
0
        private void btnSend_Click(object sender, EventArgs e)
        {
            byte[] msgSend = { 0xFF, 0x01, 0x01, 0x02 };

            txtReport.AppendText(ServerUDP.SendUdp(1901, "192.168.1.255", 1901, msgSend));
        }
Exemplo n.º 6
0
        public static void Server(string text, Player source, ServerUDP server)
        {
            string parameter = string.Empty;
            string command   = text.Substring(1);

            if (command.Contains(" "))
            {
                int spaceIndex = command.IndexOf(" ");
                parameter = command.Substring(spaceIndex + 1);
                command   = command.Substring(0, spaceIndex);
            }

            switch (command.ToLower())
            {
            case "spawn":
                var entityUpdate = new EntityUpdate()
                {
                    guid     = source.entityData.guid,
                    position = new Resources.Utilities.LongVector()
                    {
                        x = 543093329157,
                        y = 546862296355,
                        z = 14423162
                    }
                };
                server.SendUDP(entityUpdate.Data, source);
                break;

            case "load":
                server.worldUpdate.Write(source.writer);
                break;

            case "ban":
                ushort guid = 0;
                if (!source.admin || !ushort.TryParse(parameter, out guid))
                {
                    break;
                }
                break;

            case "time":
                try {
                    int index  = parameter.IndexOf(":");
                    int hour   = Convert.ToInt32(parameter.Substring(0, index));
                    int minute = Convert.ToInt32(parameter.Substring(index + 1));

                    var inGameTime = new InGameTime()
                    {
                        Time = (hour * 60 + minute) * 60000
                    };
                    server.SendUDP(inGameTime.data, source);
                } catch (Exception) {
                    //invalid syntax
                }
                break;

            case "set":
                break;

            default:
                break;
            }
        }
Exemplo n.º 7
0
 void Start()
 {
     servidor = gameObject.AddComponent <ServerUDP> () as ServerUDP;
 }