Exemplo n.º 1
0
        static void Main(string[] args)
        {
            var conn = new XSockets.Client40.XSocketClient("ws://hackzurich.cloudapp.net:8080", "http://localhost", "sensor");
            conn.QueryString.Add("sensortype", "photon");
            conn.OnConnected += (e, i) => { Console.WriteLine("Connected"); };

            var sensor = conn.Controller("sensor");

            sensor.On("ready", () =>
            {
                while (true)
                {
                    var d = new SensorData()
                    {
                        Humidity = 2.334,
                        Temperature = 23.000,
                    };

                    sensor.Invoke("wd", d);
                    System.Threading.Thread.Sleep(5000);
                }
            });

            sensor.OnOpen += (a, b) =>
            {

                var d = new SensorClientData()
                {
                    Lat = 47.367347,
                    Lng = 8.5500025,
                    Name = "Demo",
                    Organization = "XSockets",
                    SensorId = conn.PersistentId.ToString()
                };

                sensor.Invoke("ci", d);
                System.Threading.Thread.Sleep(3000);

            };

            //monitor.OnOpen += (e, i) => {
            //    Console.WriteLine("Monitor Controller Opened");
            //};
            //monitor.On<SensorClientData>("wd", (data) => {
            //    Console.WriteLine("Id:   {0}",data.SensorId);
            //    Console.WriteLine("Org:  {0}", data.Organization);
            //    Console.WriteLine("Name: {0}", data.Name);
            //    Console.WriteLine("Tmp:  {0}", data.Temperature);
            //    Console.WriteLine("Hum:  {0}", data.Humidity);
            //    Console.WriteLine("Lat:  {0}", data.Lat);
            //    Console.WriteLine("Lng:  {0}", data.Lng);
            //});

            conn.Open();

            Console.ReadLine();
        }
Exemplo n.º 2
0
        void initConnection()
        {
            Task.Delay(2000);
            var client = new XSockets.Client40.XSocketClient("ws://localhost:4502", "http://localhost", "geocars");

            client.Controller("geocars").On<GeoCar>("pos", d =>
            {
                ReceivedGeoCarEvent(d.Id, new Location() { Latitude = d.GeoData.Lat, Longitude = d.GeoData.Lng });
            });

            client.Open();
        }