0

I'm trying to access an object's property values on C#. I send my object from Node.js to C# via websockets.

I'm using this package : https://github.com/sta/websocket-sharp

Here's what I send via Node.js

var car = {
  type: "Fiat",
  model: "500",
  color: "white"
};

Here's what I see when I log the data, this is where I'm confused. Where does 40 and 42 come from?

0{
  "sid":"BWuJF1L5qN1WELSGAAAC",
  "upgrades":[],
  "pingInterval":25000,
  "pingTimeout":60000}
  40
  42[{"type":"Fiat","model":"500","color":"white"}]

My C# code

using System;
using System.Linq;
using WebSocketSharp;

namespace Example
{
    public class Program
    {
        public static void Main(string[] args)
        {
            using (var ws = new WebSocket("ws://localhost/socket.io/?EIO=2&transport=websocket"))
            {
                ws.OnMessage += (sender, e) =>
                    Console.WriteLine(e.Data);

                ws.Connect();
                Console.ReadKey(true);
            }
        }
    }
}

When I try to access it via e.Data.First(), I see the output below. I want to access car and its property values.

Why does it not work?

0
4
salep
  • 1,332
  • 9
  • 44
  • 93
  • Why are you using a custom implementation? .NET has built in support for websockets (I think from version 4.5 upwards). Or you could host a signalR websocket with Owin (katana) and asp.net core. – NtFreX Nov 20 '16 at 00:22
  • @Dr. Fre , Thanks, but I don't use asp.net or other things you've mentioned. I just want to make this work, if it's possible. I had to use C# because I'm dealing with an application written in C#, everything else is handled in Node.js so I don't want to learn a whole new language just for that.. – salep Nov 20 '16 at 00:33
  • 1
    show all the necessary code ... where does *pingInterval* etc. come from ? Show the method that send the data. – Jim Nov 20 '16 at 13:32
  • I'm using a package called websocket-sharp, I added its link. I don't know where they come from, haven't been able to analyze the whole thing. I only send the object from Node.js, the rest (ping, interval, etc) come by itself. My experience with C# is very limited, so I think I'll have to figure it out slowly since that's too much to ask here. – salep Nov 20 '16 at 13:45

0 Answers0