public void StartBroadcasting()
 {
     while (_enableBroadcasting)
     {
         if (_broadcastQueue.Count == 0)
         {
             Thread.Sleep(THREAD_WAIT_TIME);
         }
         else
         {
             JSONSkeleton packet = (JSONSkeleton)_broadcastQueue.Dequeue();
             socketClient.Send("JSONSkeleton", packet);
         }
     }
 }
		public void Execute()
		{
			Console.WriteLine("Starting TestSocketIOClient Example...");

			socket = new Client("http://127.0.0.1:3000/"); // url to the nodejs / socket.io instance

			socket.Opened += SocketOpened;
			socket.Message += SocketMessage;
			socket.SocketConnectionClosed += SocketConnectionClosed;
			socket.Error += SocketError;
			
			socket.HandShake.Headers.Add("OrganizationId", "1034");
			socket.HandShake.Headers.Add("UserId", "TestSample");

			// register for 'connect' event with io server
			socket.On("connect", (fn) =>
			{
				Console.WriteLine("\r\nConnected event...\r\n");
				Console.WriteLine("Emit Part object");

				// emit Json Serializable object, anonymous types, or strings
				//Part newPart = new Part() { X = 1, Y = 2, Z = 3 };
                //socket.Emit("JSONSkeleton", newPart);

			    JSONSkeleton newPart = new JSONSkeleton();
                socket.Emit("partInfo", newPart.ToJsonString());

			});

			
			// register for 'update' events - message is a json 'Part' object
			socket.On("update", (data) =>
			{
				Console.WriteLine("recv [socket].[update] event");
				//Console.WriteLine("  raw message:      {0}", data.RawMessage);
				//Console.WriteLine("  string message:   {0}", data.MessageText);
				//Console.WriteLine("  json data string: {0}", data.Json.ToJsonString());
				//Console.WriteLine("  json raw:         {0}", data.Json.Args[0]);

				// cast message as Part - use type cast helper
				Part part = data.Json.GetFirstArgAs<Part>();
				//Console.WriteLine(" Part Level:   {0}\r\n", part.Level);

			});

			// make the socket.io connection
			socket.Connect();
		}
Esempio n. 3
0
        public void Execute()
        {
            Console.WriteLine("Starting TestSocketIOClient Example...");

            socket = new Client("http://127.0.0.1:3000/");             // url to the nodejs / socket.io instance

            socket.Opened  += SocketOpened;
            socket.Message += SocketMessage;
            socket.SocketConnectionClosed += SocketConnectionClosed;
            socket.Error += SocketError;

            socket.HandShake.Headers.Add("OrganizationId", "1034");
            socket.HandShake.Headers.Add("UserId", "TestSample");

            // register for 'connect' event with io server
            socket.On("connect", (fn) =>
            {
                Console.WriteLine("\r\nConnected event...\r\n");
                Console.WriteLine("Emit Part object");

                // emit Json Serializable object, anonymous types, or strings
                //Part newPart = new Part() { X = 1, Y = 2, Z = 3 };
                //socket.Emit("JSONSkeleton", newPart);

                JSONSkeleton newPart = new JSONSkeleton();
                socket.Emit("partInfo", newPart.ToJsonString());
            });


            // register for 'update' events - message is a json 'Part' object
            socket.On("update", (data) =>
            {
                Console.WriteLine("recv [socket].[update] event");
                //Console.WriteLine("  raw message:      {0}", data.RawMessage);
                //Console.WriteLine("  string message:   {0}", data.MessageText);
                //Console.WriteLine("  json data string: {0}", data.Json.ToJsonString());
                //Console.WriteLine("  json raw:         {0}", data.Json.Args[0]);

                // cast message as Part - use type cast helper
                Part part = data.Json.GetFirstArgAs <Part>();
                //Console.WriteLine(" Part Level:   {0}\r\n", part.Level);
            });

            // make the socket.io connection
            socket.Connect();
        }
Esempio n. 4
0
 public void Send(object objectType, JSONSkeleton jsonObject)
 {
     socket.Emit("partInfo", jsonObject.ToJsonString());
 }
 public void Send(object objectType, JSONSkeleton jsonObject)
 {
     socket.Emit("partInfo", jsonObject.ToJsonString());
 }