Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Integrating Socket.io 1.0 client with c# program

I'm new to sockets and I've been trying to integrate a Socket.io 1.0 client in my C# program without much success.

I'm using SocketIoClientDotNet to do the job, which is the only option I've found which supports socket.io 1.0 (for instance SocketIO4Net.Client only supports 0.9, unfortunately). The program was initially targeting .NET framework 4.0 which I have to change for compatibility with SocketIoClientDotNet which apparently supports .Net 3.5 and 4.5.

A snippet of my code:

using SteamKit2;
using SteamTrade;
using SteamTrade.TradeWebAPI;
using SteamTrade.TradeOffer;
using System;
using System.IO;
using System.Net;
using System.Timers;
using System.Threading;
using System.Threading.Tasks;
using System.Text.RegularExpressions;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Text;
using System.Linq;
using System.Diagnostics;
using System.Web.Script.Serialization;
using Newtonsoft.Json;
using MySql.Data.MySqlClient;
using Quobject.SocketIoClientDotNet.Client;
using Quobject.EngineIoClientDotNet.Client.Transports;
using Quobject.EngineIoClientDotNet.ComponentEmitter;
using Quobject.EngineIoClientDotNet.Modules;
using Quobject.EngineIoClientDotNet.Parser;
using Socket = Quobject.SocketIoClientDotNet.Client.Socket;

namespace Foo
{
    public class Bar
    {
        public override void fooBar()
        {
            // just to test, didn't go any further because of errors
            var socket = IO.Socket("http://localhost");
            socket.On(Socket.EVENT_CONNECT, () =>
            {
                socket.Emit("hi");
                socket.On("hi", (data) =>
                {
                    Console.WriteLine(data);
                    socket.Disconnect();
                });
            });

            // more code...
        }

        // more code...
    }
}

This is where the problems begin:

SocketIoClientDotNet adds a reference to System.Threading.Tasks.NET35.

»» Targeting .Net Framework 4.0 or 4.5 without removing the reference causes the error:

Error   17  The type 'System.Threading.Tasks.Task<TResult>' exists in both 'c:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0\mscorlib.dll' and 'c:\MyApp\trunk\packages\System.Threading.Tasks.Unofficial.3.1\lib\net35\System.Threading.Tasks.NET35.dll'

»» Changing the target framework to 3.5 causes other dependencies to break with Error 396 The type or namespace name 'FooBar' could not be found (are you missing a using directive or an assembly reference?) , so I can't do that as well.

»» Removing the reference to System.Threading.Tasks.NET35 causes a System.IO.FileNotFoundException Exception by Quobject.SocketIoClientDotNet.Client.IO

Essentially I'm stuck here and in need of guidance. Any help and sugestion on how to get Socket.io 1.0 working here will be greatly appreciated. Thanks!

like image 375
bockzior Avatar asked Dec 06 '25 08:12

bockzior


1 Answers

Apparently the problem was caused because SocketIoClientDotNet was installed when targeting .Net 4.0, which wrongly required System.Threading.Tasks.NET35. Targeting the .Net 4.5 and only then reinstalling SocketIoClientDotNet solved the issue.

like image 102
bockzior Avatar answered Dec 07 '25 22:12

bockzior



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!