static async Task RunSample() { var peer = new Peer("localhost", 50052); peer.StartServer(); await peer.ConnectDirectory("localhost", 50051); var numbers = await peer.GetChannel("numbers"); long fromIndex = 0; long toIndex = 0; while (true) { toIndex = fromIndex + 2; lock (terminateLock) { if (shouldTerminate) { Console.WriteLine("Shutting down..."); peer.StopServer().Wait(); break; } } var result = await numbers.Get(fromIndex, toIndex); fromIndex = toIndex; foreach (var message in result) { var content = message.Content; Array.Reverse(content); var number = BitConverter.ToInt64(content); Console.WriteLine($"App2 read {number} from numbers channel"); } Thread.Sleep(5000); } }
static async Task RunSample() { Console.WriteLine("Running App 1"); var peer = new Peer("localhost", 50053); peer.StartServer(); await peer.ConnectDirectory("localhost", 50051); var numbers = await peer.CreateChannel("numbers"); long current = 0; while (true) { lock (terminateLock) { if (shouldTerminate) { Console.WriteLine("Shutting down..."); peer.StopServer().Wait(); break; } } var content = BitConverter.GetBytes(current); Array.Reverse(content); var message = new Message() { Content = content, Timestamp = current }; Console.WriteLine($"App 1 has written {current} to numbers channel"); await numbers.Put(message); current++; Thread.Sleep(3000); } }