static void Main(string[] args) { var conn = new XSocketClient("ws://localhost:4502","http://localhost","IoT"); conn.Controller("IoT").OnOpen += (sender, connectArgs) => Console.WriteLine("IoT Controller Connected"); conn.Open(); //Set client type conn.Controller("IoT").SetEnum("ClientType","Native"); //Listen for messages from the Netduino conn.Controller("IoT").On<ChatMessage>("chatmessage", message => Console.WriteLine(message.Text)); Console.WriteLine("Listening for messages from the Netduino, hit enter to quit"); Console.ReadLine(); }
static void Main(string[] args) { //Connect to the XSockets instance hosted in Owin var c = new XSocketClient("ws://localhost:12345", "http://localhost", "stock"); c.OnConnected += (sender, eventArgs) => Console.WriteLine("CONNECTED"); c.Open(); //Set the 'mystocks' property on the controller to 'MSFT' and 'XNET' c.Controller("stock").SetProperty("MyStocks", new List<string>() { "MSFT", "XNET" }); //Listen for 'tick', but we use dynamic since we have no reference to the class Stock c.Controller("stock").On<Stock>("tick", s => { Console.WriteLine("{0}:{1}",s.Symbol, s.Price); }); Console.ReadLine(); }
static void Main(string[] args) { using (var container = XSockets.Plugin.Framework.Composable.GetExport<IXSocketServerContainer>()) { //Start a server container.Start(); Console.WriteLine("Hit enter to start a client that will show Serilog.Sinks.XSockets"); Console.ReadLine(); //Start a client and hook up only to the log controller... var client = new XSocketClient("ws://localhost:4502","http://localhost","log"); client.Open(); client.Controller("log").On<LogEventWrapper>("logEvent", logEvent => { Console.ForegroundColor = ConsoleColor.Cyan; Console.WriteLine("Message: {0}",logEvent.RenderedMessage); Console.ResetColor(); }); //Change the LogEventLevel the client listens to every 8 seconds Task.Factory.StartNew(() => { while (true) { var newLevel = ((LogEventLevel)new Random().Next(0, 5)).ToString(); client.Controller("log").SetEnum("LogEventLevel", newLevel); Console.ForegroundColor = ConsoleColor.Green; Console.WriteLine("New LogEventLevel set to {0}", newLevel); Console.ResetColor(); Thread.Sleep(8000); } }); Console.WriteLine("Hit enter to quit"); Console.ReadLine(); } }
static void Main(string[] args) { //Wait for server to start Task.Delay(10000).Wait(); var connection = new XSocketClient("ws://localhost:4502", "http://localhost", "Notification"); IController controller = connection.Controller("Notification"); connection.OnConnected += (sender, eventArgs) => Console.WriteLine("Connected to host"); connection.Open(); controller.OnOpen += (sender, eventArgs) => Console.WriteLine("Ready to send messages!"); controller.OnError += (sender, errorArgs) => Console.WriteLine("An error occured: " + errorArgs.Exception); string message = null; while (message != "q") { message = Console.ReadLine(); controller.Invoke("sendmessage", message); } }