Exemple #1
0
        public Task <string> OpenAsync(CancellationToken cancellationToken)
        {
            _netNode.Start();
            var ipAddress = FabricRuntime.GetNodeContext().IPAddressOrFQDN;

            return(Task.FromResult($"{_transportSchema}://{ipAddress}:{_netNode.Address.Port}"));
        }
        async static Task Run(INetNode node)
        {
            node.Start();
            Console.WriteLine("Input server endpoint in form of ipaddress:port");
            string[] addressAndPort = Console.ReadLine().Split(':');
            var      endpoint       = new IPEndPoint(IPAddress.Parse(addressAndPort[0]), int.Parse(addressAndPort[1]));

            //before doing any network comms we should connect to some server node
            using (INetChannel channel = await node.Connect(endpoint))
            {
                await Task.Yield();

                Console.WriteLine("Enter your name");
                string name = Console.ReadLine();

                Console.WriteLine("Enter chat room name");
                string roomName = Console.ReadLine();

                //using connected channel we can send in request/reply pattern
                JoinRoomResponse response = await channel.SendRequestAsync <JoinRoomResponse>(
                    new JoinRoom
                {
                    ClientName = name,
                    RoomName   = roomName
                });

                if (response.RetCode == JoinRoomRetCode.NameIsTaken)
                {
                    Console.WriteLine("Name is taken");
                    return;
                }

                Console.WriteLine("You are connected, say something or enter exit");

                bool exit = false;
                while (!exit)
                {
                    await Task.Yield(); //client uses single threaded processing, so it's better noto block it with Console.Readline

                    string text = Console.ReadLine();
                    if (text == "exit")
                    {
                        exit = true;
                    }
                    else
                    {
                        //or we can send just one way messages
                        channel.Send(new Say {
                            Text = text
                        });
                    }
                }
            }
        }
        async static Task Run(INetNode node)
        {
            node.Start();
            Console.WriteLine("Input server endpoint in form of ipaddress:port");
            string[] addressAndPort = Console.ReadLine().Split(':');
            var endpoint = new IPEndPoint(IPAddress.Parse(addressAndPort[0]), int.Parse(addressAndPort[1]));

            //before doing any network comms we should connect to some server node
            using (INetChannel channel = await node.Connect(endpoint))
            {
                await Task.Yield();
                Console.WriteLine("Enter your name");
                string name = Console.ReadLine();

                Console.WriteLine("Enter chat room name");
                string roomName = Console.ReadLine();

                //using connected channel we can send in request/reply pattern
                JoinRoomResponse response = await channel.SendRequestAsync<JoinRoomResponse>(
                    new JoinRoom
                    {
                        ClientName = name,
                        RoomName = roomName
                    });

                if (response.RetCode == JoinRoomRetCode.NameIsTaken)
                {
                    Console.WriteLine("Name is taken");
                    return;
                }

                Console.WriteLine("You are connected, say something or enter exit");

                bool exit = false;
                while (!exit)
                {
                    await Task.Yield(); //client uses single threaded processing, so it's better noto block it with Console.Readline
                    string text = Console.ReadLine();
                    if (text == "exit")
                    {
                        exit = true;
                    }
                    else
                    {
                        //or we can send just one way messages
                        channel.Send(new Say {Text = text});
                    }
                }
            }
        }