1

I'm using the following java script code as client to show real time data in my website

  const socket = io('https://mysocketio.com/', {
                timeout: 2000,
                forceNew: true,
                path: '/socket/',
                query: {
                    token: "AbcD"
                },
                transports: ['websocket'],
                reconnection: true
            });

            socket.on('connect', function () {
               alert('connected');
            });


            socket.on('change', function (liveData) {
               // live data processing

            });
            socket.on('disconnect', function () {
                alert('disconnect');
            }); 

The above code is working fine. Now my client wants to do the same in desktop application too. So please help me to show real time data in to desktop application using C# or VB as client code.

Thanks a lot.

Prince
  • 11
  • 3
  • Are you asking for people to translate this to C#? Or whether there's web socket support in .NET? There is, through the [WebSocket](https://learn.microsoft.com/en-us/dotnet/api/system.net.websockets.websocket?view=netcore-3.1) class – Panagiotis Kanavos Jun 05 '20 at 08:15
  • I'm new to win forms/socket programming. Im just want C# snippet for call socket.io into windows application using headers like above js code. Thanks. – Prince Jun 05 '20 at 08:31
  • SO isn't a translation service though, it's a Q&A site about specific programming problems. Have you tried writing anything? Have you tried using the WebSocket class? If you can't even create a desktop application, you won't be able to write the code that calls WebSocket. There are a *lot* of SO questions about WebSocket too – Panagiotis Kanavos Jun 05 '20 at 08:39
  • And a lot of SO questions about using socket.io specifically, that point to numerous socket.io clients in NuGet – Panagiotis Kanavos Jun 05 '20 at 08:40
  • I'm already created a windows app and I got an error. Thats why I asked this query. I raised another query regarding this please have a look [here](https://stackoverflow.com/questions/62212272/how-to-get-real-time-data-using-socket-io-to-a-win-form-using-c-sharp). – Prince Jun 05 '20 at 09:39
  • Where's that code, what error? What library did you use? You won't get any answers for incomplete questions – Panagiotis Kanavos Jun 05 '20 at 09:45

1 Answers1

0

I would use web sockets with Reactive Extensions this answer might be helpful.

Mohsen
  • 4,000
  • 8
  • 42
  • 73
  • 1
    For starters, this should be a comment as it doesn't actually answer the question. Second, the OP is actually asking for a translation from Java to C#. The code isn't event-based so simply using `async/await` would work – Panagiotis Kanavos Jun 05 '20 at 08:12
  • 1
    @Mohsen, It's working perfectly.Thank you very much!. – Prince Jun 05 '20 at 13:13