private static void ConnectToTcpServer() { var connected = false; while (!connected) { Console.WriteLine("Looking for server..."); try { Osprey.Locate("osprey.server") .Stream("mango") .Subscribe(msg => Console.WriteLine("MSG: " + msg.ToString())); connected = true; } catch { // ignored } Thread.Sleep(2000); } Console.WriteLine("Connected."); }
static void Main(string[] args) { Console.WriteLine("========== OSPREY SERVER =========="); using (Osprey.Default()) using (Osprey.Join("osprey.server")) using (var tcp = new TcpServer("mango")) { StartSendingHttp(); Task.Run(() => { while (true) { tcp.Broadcast(Guid.NewGuid().ToString()); Thread.Sleep(100); } }); while (true) { Thread.Sleep(1000); } } }
private static void StartSendingHttp() { Task.Factory.StartNew(async() => { while (true) { try { var task = Osprey.Locate("osprey.client") .Http() .Send(new HttpMessage <string, string> { Endpoint = "test", Payload = "apples", RequestType = HttpVerb.GET }); var response = await task; Console.WriteLine("RESPONSE: " + response); } catch (Exception ex) { Console.WriteLine(ex.Message); } Thread.Sleep(4000); } }, TaskCreationOptions.LongRunning); }
static void Main(string[] args) { using (Osprey.Default()) using (Osprey.Join("osprey.monitor")) { while (true) { Console.Clear(); Console.WriteLine("========== OSPREY MONITOR =========="); Console.WriteLine(""); PrintDiscovered(); Thread.Sleep(2000); } } }
static void Main(string[] args) { Console.WriteLine("========== OSPREY CLIENT =========="); using (Osprey.Default()) using (Osprey.Join("osprey.client")) using (new TcpServer("tcp1")) using (new TcpServer("tcp2")) using (new TcpServer("tcp3")) using (new HttpServer <DefaultStartup <DefaultNancyBootstrapper> >("http")) { ConnectToTcpServer(); while (true) { Thread.Sleep(1000); } } }