gpt4 book ai didi

c# - 将 Socket.io 1.0 客户端与 c# 程序集成

转载 作者:太空宇宙 更新时间:2023-11-03 13:12:58 24 4
gpt4 key购买 nike

我是套接字的新手,我一直在尝试将 Socket.io 1.0 客户端集成到我的 C# 程序中,但没有取得太大成功。

我正在使用 SocketIoClientDotNet完成这项工作,这是我发现的唯一支持 socket.io 1.0 的选项(例如 SocketIO4Net.Client 不幸的是只支持 0.9)。该程序最初针对 .NET framework 4.0,我必须更改它以与 SocketIoClientDotNet 兼容。显然支持 .Net 3.5 和 4.5。

我的代码片段:

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...
}
}

这就是问题开始的地方:

SocketIoClientDotNet添加对 System.Threading.Tasks.NET35 的引用。

»» 在不删除引用的情况下定位 .Net Framework 4.0 或 4.5 会导致错误:

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'

»» 将目标框架更改为 3.5 会导致其他依赖项中断并出现 错误 396 找不到类型或 namespace 名称“FooBar”(是否缺少 using 指令或程序集引用?),所以我也不能那样做。

»» 删除对 System.Threading.Tasks.NET35 的引用会导致 System.IO.FileNotFoundException 异常 Quobject.SocketIoClientDotNet.Client.IO

基本上我被困在这里,需要指导。非常感谢任何有关如何让 Socket.io 1.0 在这里工作的帮助和建议。谢谢!

最佳答案

显然问题是因为在面向 .Net 4.0 时安装了 SocketIoClientDotNet,它错误地需要 System.Threading.Tasks.NET35。以 .Net 4.5 为目标,然后重新安装 SocketIoClientDotNet 解决了这个问题。

关于c# - 将 Socket.io 1.0 客户端与 c# 程序集成,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27678628/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com