You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

SuperSocket Telnet示例运行报错:Operation is not supported on this platform

SuperSocket Telnet服务端PlatformNotSupportedException问题解决

错误原因

  1. 版本平台兼容问题:你使用的SuperSocket v1.6是针对.NET Framework开发的旧版本,依赖了仅.NET Framework支持的异步委托调用(如错误栈中的SessionHandler1.BeginInvoke),在.NET Core/.NET 5+等跨平台环境下运行时,会触发PlatformNotSupportedException`。
  2. 事件注册时机错误:代码中NewSessionConnected事件是在服务启动后才绑定的,若服务启动后立即有客户端连接,会因事件未绑定导致逻辑不执行,甚至可能引发异常。

解决方法

1. 升级到跨平台版本

放弃老旧的v1.6版本,使用支持跨平台的SuperSocket新版本(如SuperSocket.NetCore),通过NuGet安装对应包即可。新版本移除了.NET Framework专属API依赖,可在.NET Core/.NET 5+环境正常运行。

2. 调整事件注册时机(适配v1.6)

若需保留v1.6版本,需将事件绑定代码移到服务启动前,确保服务启动时已完成事件监听:

using SuperSocket.SocketBase;

Console.WriteLine("Press any key to start the server!");
Console.ReadKey();
Console.WriteLine();

var appServer = new AppServer();

// 先绑定事件,再启动服务
appServer.NewSessionConnected += appServer_NewSessionConnected;

static void appServer_NewSessionConnected(AppSession session)
{
    session.Send("Welcome to SuperSocket Telnet Server");
}

if (!appServer.Setup(2023))
{
    Console.WriteLine("Failed to setup!");
    Console.ReadKey();
    return;
}

Console.WriteLine();

if (!appServer.Start())
{
    Console.WriteLine("Failed to start!");
    Console.ReadKey();
    return;
}

Console.WriteLine("The server started successfully, press key 'q' to stop it!");

while (Console.ReadKey().KeyChar != 'q')
{
    Console.WriteLine();
    continue;
}

appServer.Stop();
Console.WriteLine("The server was stopped!");
Console.ReadKey();

3. 匹配运行环境(适配v1.6)

坚持使用v1.6时,必须将项目目标框架设置为.NET Framework(如4.6.1及以上),不能使用.NET Core/.NET 5+,否则仍会出现平台不支持错误。

内容的提问来源于stack exchange,提问作者sangeun jo

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.14 00:04:59