コード例 #1
0
        protected override void LoadContent()
        {
            // Create a new SpriteBatch, which can be used to draw textures.
            spriteBatch = new SpriteBatch(GraphicsDevice);

            // TODO: use this.Content to load your game content here



            dummyTexture = new Texture2D(GraphicsDevice, 1, 1);
            dummyTexture.SetData(new Color[] { Color.White });

            gp = new GamePad(new Rectangle(1540 * 2 / 3, 540 * 2 / 3, 260 * 2 / 3, 540 * 2 / 3), new Rectangle(30 * 2 / 3, 800 * 2 / 3, 700 * 2 / 3, 270 * 2 / 3), dummyTexture);

            //   IPSender.refreshIP();
            //rc = new FixedSpeedRobotController(ReceivedFrame, 90, 24);
            //rc.start();
            tcp = new TCPCommunicator(IPSender.getIP(), 4817);
            udp = new UDPCommunication(IPSender.getIP(), 4818, ReceivedFrame);
            Thread t = new Thread(x => tcpCommunication());

            t.Start();
            Thread t2 = new Thread(x => udpCommunication());

            t2.Start();
        }
コード例 #2
0
        private async void udpCommunication()
        {
            string    ip   = IPSender.getIP();
            UdpClient udpw = new UdpClient();

            Console.WriteLine("UDP connection ok");
            // recieve data from any ip address and any port
            IPEndPoint remotew = new IPEndPoint(IPAddress.Any, 4819);//= new IPEndPoint(IPAddress.Parse(ip), 4818);

            udpw.Connect(ip, 4819);
            udpw.Send(new byte[] { 100, 101 }, 2);
            Thread.Sleep(1000);
            Console.WriteLine("UDP server started");
            UdpClient udp = new UdpClient();

            Console.WriteLine("UDP connection ok");
            // recieve data from any ip address and any port
            IPEndPoint remote = new IPEndPoint(IPAddress.Any, 4818);//= new IPEndPoint(IPAddress.Parse(ip), 4818);

            udp.Connect(ip, 4818);
            udp.Send(new byte[] { 100, 101 }, 2);

            //UdpClient udp = new UdpClient(4818);
            //IPEndPoint remote = new IPEndPoint(IPAddress.Any, 4818);



            while (true)
            {
                byte[] byte_Of_Frame = udp.Receive(ref remote);

                //   Console.WriteLine("received goodies" + byte_Of_Frame[0].ToString() + "." + byte_Of_Frame[1].ToString() + " in " + sw.ElapsedMilliseconds);
                frameManager.receivePackage(byte_Of_Frame);
            }
        }