'Using Socket.IO in C#
I'm trying to read a Socket.IO stream from Wikimedia sites. There is sample code for various languages, but I need to get this working in C#
The source link is here:
https://wikitech.wikimedia.org/wiki/RCStream
And here is the JavaScript implementation.
// Requires socket.io-client 0.9.x:
// browser code can load a minified Socket.IO JavaScript library;
// standalone code can install via 'npm install [email protected]'.
var io = require( 'socket.io-client' );
var socket = io.connect( 'stream.wikimedia.org/rc' );
socket.on( 'connect', function () {
socket.emit( 'subscribe', 'commons.wikimedia.org' );
} );
socket.on( 'change', function ( data ) {
console.log( data.title );
} );
I've tried about 3 or so .NET versions of socket.io and have been unable to get a connection. The closest I've come is getting an "invalid endpoint" error message. I think part of the problem is some of the libraries I was using (from Nuget and other places) where different versions of socket.io 0.9.x
I was hoping someone here could help me find a way of getting this working in C#. I've spent about 4 hours to no avail. Thanks.
Solution 1:[1]
You can take a look on a C# client for Socket.IO like SocketIoClientDotNet or SocketIO4net so your code would be as simple as in JS.
var socket = IO.Socket("http://stream.wikimedia.org/rc");
socket.On(Socket.EVENT_CONNECT, () =>
{
socket.Emit("hi");
});
socket.On("connect", (data) =>
{
socket.Emit("subscribe", "commons.wikimedia.org");
});
socket.On("change", (data) =>
{
Console.WriteLine(data.title);
});
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Anton K |