Beispiel #1
0
        static void Main(string[] args)
        {
            AoInterface receiverNetwork = new Network(new IPEndPoint(IPAddress.Parse("127.0.0.1"), 15000));
            AoInterface receiverFile = new FileSystemDLL("output.xml");
            Console.WriteLine("Do you want to subscribe? (Y/N)");
            string n = Console.ReadLine();
            if (n.Equals("Y"))
            {
                receiverNetwork.WriteAsync("subscriber");
            }

            else
            {
                Console.WriteLine("Thank you. You can press enter to exit");
                Console.ReadKey();
                System.Environment.Exit(1);
            }

            Task t = Task.Factory.StartNew(
                async () =>
                {
                    string m;
                    Console.ReadKey();

                    while ((m = await receiverNetwork.ReadAsync()) != "1")
                    {
                        Console.WriteLine(m);
                        receiverFile.WriteAsync(m);
                    }
                });

            t.Wait();
            Console.ReadKey();
        }
        static void Main(string[] args)
        {
            Print();

            ////sender
            AoInterface fileObj = new FileSystemDLL("test.xml");

            ////// serialization of XML file
            Task<string> dataReturns = fileObj.ReadAsync();
            AoInterface networkObj = new Network(new IPEndPoint(IPAddress.Parse("127.0.0.1"), 15000));

            Task t = Task.Factory.StartNew(
                 () =>
                 {
                    networkObj.WriteAsync(dataReturns.Result);
                    Console.WriteLine("Message Sent");
                 });

            t.Wait();
            Console.ReadLine();
        }
Beispiel #3
0
 private void start_nw_join()
 {
     network = new Network(data);
     //network.join_connection();
     //view.newGame();
 }
Beispiel #4
0
        private void start_nw_host()
        {
            data.Current_player = data.Options["Start Player"]; // should be host
            data.Stage = Data.Gamestage.NoClick;
            nw = new Network(data);

            //t1 = new Thread(threaded_start_nw_host);
            //t1.Start();

            bw = new BackgroundWorker();
            bw.DoWork += Bw_DoWork;
            bw.RunWorkerCompleted += Bw_RunWorkerCompleted;
            bw.WorkerSupportsCancellation = true;
            bw.RunWorkerAsync();

            waitDialogue();

            // this loop, polls the result of the thread operation
            // but it is this loop which is freezing the gui
            //while (! nw.isConnect())
            //{
            //    Thread.Sleep(2000);
            //    System.Console.WriteLine("t1 not connected yet");
            //}

            //System.Console.WriteLine("t1 has established connection");

            //view.newGame();
        }