Beispiel #1
0
        public static void CommClientPC_Test()
        {
            CommClientPC client = null;

            IPAddress adresInterfejsuDoNasluchu = CommClientPC.GetLocalIPAddress();

            Console.WriteLine("Nasluchiwanie na adresie: " + adresInterfejsuDoNasluchu.ToString());

            client = new CommClientPC(adresInterfejsuDoNasluchu, Console.WriteLine);


            string input = null;

            while (client.IsConnected == true)
            {
                input = Console.ReadLine();
                if (client.IsConnected == true)
                {
                    if (input == "plik")
                    {
                        Console.WriteLine("path");
                        client.SendFile(Console.ReadLine());
                    }
                    else
                    {
                        client.SendMessage(input);
                    }
                    if (input == "x")
                    {
                        client.Close();
                    }
                }
            }
            Console.ReadLine();
        }
Beispiel #2
0
        private void Advertise_T()
        {
            IPAddress  localIPAddress   = CommClientPC.GetLocalIPAddress();
            IPEndPoint localNICEndPoint = new IPEndPoint(localIPAddress, 50000);
            UdpClient  client           = new UdpClient(localNICEndPoint);

            byte[] sendBytes = Encoding.UTF8.GetBytes(localIPAddress.ToString());
            client.EnableBroadcast   = true;
            client.MulticastLoopback = true;
            IPEndPoint broadcastIP = new IPEndPoint(IPAddress.Broadcast, 50000);

            while (StillSend("udp ping on IP:" + localIPAddress.ToString()) == true)
            {
                client.Send(sendBytes, sendBytes.Length, broadcastIP);
                Thread.Sleep(1000);
            }

            EndingEvent();

            client.Close();
        }
Beispiel #3
0
        private void Send_T(int _seconds)
        {
            StillSend = true;
            int i = 0;

            IPAddress  localIPAddress   = CommClientPC.GetLocalIPAddress();
            IPEndPoint localNICEndPoint = new IPEndPoint(localIPAddress, 50000);
            UdpClient  client           = new UdpClient(localNICEndPoint);

            byte[] sendBytes = Encoding.UTF8.GetBytes(localIPAddress.ToString());
            client.EnableBroadcast   = true;
            client.MulticastLoopback = false;
            IPEndPoint broadcastIP = new IPEndPoint(IPAddress.Broadcast, 50000);

            while (i < _seconds && StillSend == true)
            {
                client.Send(sendBytes, sendBytes.Length, broadcastIP);
                i++;
                Thread.Sleep(1000);
                //Console.WriteLine("wsylana");
            }
        }