示例#1
0
        static void Main(string[] args)
        {
            Host     host = new Host();
            RUDPPeer peer = host.CreateRUDPPeer();

            peer.OnConnectionStatusChange += (ZNet.ConnectonStaus status, ZNet.RemotePeer RemotePeer) =>
            {
                Console.WriteLine("Main: Connection status change to: " + status);
            };

            peer.OnMessageReceive += (string data, ZNet.RemotePeer RemotePeer) =>
            {
                Console.WriteLine("Main: Message received: " + data);
            };

            string IPV4 = "127.0.0.1";

            peer.Bind(ref IPV4, 42);

            while (0 == 0)
            {
                host.ServiceAllPeers();
            }
            host.Destroy();
        }
示例#2
0
        static void Main(string[] args)
        {
            Host       host = new ZNet.Host();
            RemotePeer remotepeer;
            //List<RemotePeer> remotePeerlist = new List<RemotePeer>();
            //for (int i = 0; i < 10; i++)
            //{
            RUDPPeer tmp = host.CreateRUDPPeer();

            tmp.OnConnectionStatusChange += (ZNet.ConnectonStaus status, ZNet.RemotePeer RemotePeer) =>
            {
                Console.WriteLine("Main: Connection status change to: " + status);
                remotepeer = RemotePeer;
            };

            tmp.OnMessageReceive += (string data, ZNet.RemotePeer RemotePeer) =>
            {
                //Console.WriteLine("Main: Message received: " + data);
            };

            remotepeer = tmp.Connect("127.0.0.1", 42);

            //    remotePeerlist.Add(remotepeer);
            //}



            int send  = 0;
            int index = 0;

            while (0 == 0)
            {
                host.ServiceAllPeers();
                //if (send >= 0)
                //{
                //    string tmpstr = send.ToString();
                //    remotepeer.Send(ref tmpstr);
                //    send--;
                //}
                if (Console.KeyAvailable)
                {
                    ConsoleKeyInfo key = Console.ReadKey(true);
                    switch (key.Key)
                    {
                    case ConsoleKey.S:
                        Console.WriteLine("Read key and send message.");
                        string tmpk = key.ToString();
                        while (index < 1000)
                        {
                            string tmpstr = send.ToString();
                            tmpstr = "Data" + tmpstr;
                            remotepeer.Send(ref tmpstr);
                            send++;
                            index++;
                        }
                        index = 0;

                        /*var rpeer = remotePeerlist.GetEnumerator();
                         * while (rpeer.MoveNext())
                         * {
                         *  rpeer.Current.Send(ref tmp);
                         * }*/
                        //remotepeer.Send(ref tmpk);
                        break;

                    default:
                        break;
                    }
                }
            }
            host.Destroy();
        }