【发布时间】:2021-01-17 12:34:45
【问题描述】:
目前我正在使用 REST 通过我的控制台应用程序使用来自外部服务/服务器的数据,但这不是很实时。
谁能提供一个非常基本的工作示例,说明如何将 .net 核心控制台应用程序连接到 wss://echo.websocket.org?
我已经开始了:
using System;
using System.Net.WebSockets;
namespace websocket
{
class Program
{
static void Main(string[] args)
{
using (var ws = new WebSocket("wss://echo.websocket.org"))
{
}
}
}
}
但是new WebSocket("wss://echo.websocket.org")) 显示错误Cannot create an instance of the abstract type or interface 'WebSocket' [websocket]csharp(CS0144)
【问题讨论】:
-
WebSocket Class是.Net 中的抽象类,不能实例化抽象类。请看链接:docs.microsoft.com/en-us/dotnet/api/… -
试试这个c-sharpcorner.com/article/…或者这个链接:c-sharpcorner.com/article/…来实现你的WebSocket客户端