Example #1
0
 public receiver()
 {
     InitializeComponent();
     _Grid.Height = Sizes.Height;
     _Grid.Width = Sizes.Width;
     volumeController = new _volumeController();
 }
Example #2
0
        private void checkAccess()
        {
            while (deviceListReceiver.Thrd.IsAlive)
            {
                IP = deviceListReceiver.IP;
            }
            Socket socket = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);     //create new socket

            IPEndPoint receiverIP = new IPEndPoint(IPAddress.Any, 810);     //end point to listen 810
            socket.Bind(receiverIP);        //listen  810 port

            IPEndPoint senderIP = new IPEndPoint(IPAddress.Any, 0);     //end point to answer
            EndPoint Remote = (EndPoint)(senderIP);
            int size = 0;
            do
            {
                if (socket.Available > 0)
                {
                    byte[] data = new byte[256];      //array that will save ping message
                    size = socket.ReceiveFrom(data, ref Remote);       //read message to data
                    Array.Resize(ref data, size);
                    if (System.Text.Encoding.Default.GetString(data) == Password)
                    {
                        _volumeController volumeController = new _volumeController();
                        byte[] checkFlag = Encoding.ASCII.GetBytes(volumeController.Volume.ToString());
                        socket.SendTo(checkFlag, checkFlag.Length, SocketFlags.None, _getHost(Remote.ToString(), 811));    //send answer to 811 port
                        break;
                    }
                    else
                    {
                        byte[] checkFlag = Encoding.ASCII.GetBytes("false");
                        socket.SendTo(checkFlag, checkFlag.Length, SocketFlags.None, _getHost(Remote.ToString(), 811));    //send answer to 811 port
                    }
                }
                Thread.CurrentThread.Join(0);
            } while (true);
            socket.Dispose();
            socket.Close();
        }