Example #1
0
        static void Main(string[] args)
        {
            var handle = GetConsoleWindow();

            // Hide
            ShowWindow(handle, SW_HIDE);

            NetworkDiscover.SendConnectionInfo().GetAwaiter().GetResult();
            ListenTCP().GetAwaiter().GetResult();



            Console.ReadLine();
        }
Example #2
0
        static async Task <string> ListenTCP()
        {
            IPAddress ipaddr = IPAddress.Parse(NetworkDiscover.GetAllLocalIPv4(NetworkInterfaceType.Wireless80211).FirstOrDefault());

            Console.WriteLine("Listening...");
            int portNumber = 12835;

            TCPLIstener tcp = new TCPLIstener(ipaddr, portNumber);

            if (!tcp.GetActive())
            {
                tcp.Start();
            }

            Console.WriteLine(ipaddr.ToString());


            while (true)
            {
                Socket client = tcp.AcceptSocket();
                Console.WriteLine("Connection accepted");


                var childSocketThread = new Thread(() =>
                {
                    byte[] data = new byte[2000];
                    int size    = client.Receive(data);

                    Console.WriteLine("Recieved data: ");
                    var comanda = Encoding.ASCII.GetString(data);
                    Console.WriteLine(comanda);
                    Console.WriteLine();

                    var response        = CommandParse.Parse(comanda);
                    byte[] responseData = Encoding.ASCII.GetBytes(response);
                    client.Send(responseData);


                    client.Close();
                });

                childSocketThread.Start();
            }
        }