WebSocket4Net简单示例失败,"操作已在进行中"

时间:2017-10-17 11:32:13

标签: xamarin runtime-error websocket4net

我试图通过Xamarin和WebSocket4Net进行简单的测试,但是在#(操作已经在进行中")的Open()上失败了。示例代码如下:

using Xamarin.Forms;
using WebSocket4Net;
using System;
using SuperSocket.ClientEngine;

namespace SocketTest
{
    public partial class SocketTest : ContentPage
    {
        private WebSocket websocket;
        public SocketTest()
        {
            InitializeComponent();

        }

        void Handle_Clicked(object sender, System.EventArgs e)
        {
            websocket = new WebSocket("ws://echo.websocket.org/");
            websocket.Opened += Websocket_Opened;
            websocket.Error += Websocket_Error;
            websocket.Closed += Websocket_Closed;
            websocket.MessageReceived += Websocket_MessageReceived;
            websocket.Open();
        }

        private void Websocket_Error(object sender, ErrorEventArgs e)
        {
            Console.WriteLine(e.Exception.Message);
        }

        private void Websocket_MessageReceived(object sender, EventArgs e)
        {
            Console.WriteLine(e.ToString());
        }

        private void Websocket_Closed(object sender, EventArgs e)
        {
            Console.WriteLine(e.ToString());
        }

        private void Websocket_Opened(object sender, EventArgs e)
        {
            websocket.Send("Hello World!");
        }
    }
}

我从标准的多平台项目(PCL)开始,并添加了一个按钮来启动连接。

Versions:
0.15.0 WebSocket4Net
0.8.0.13 SuperSocket

PCL配置为:.NET Standard Platform = netstandard1.4

我是.NET / Xamarin的新手,但我背后有多年的软件开发。

1 个答案:

答案 0 :(得分:1)

我对0.15有同样的问题。你有没有尝试降级到0.14,并删除SuperSocket?

有关于此问题的GitHub问题。

Getting this error when trying to connect in StartReceive()

以下是摘录:

Excerpt from GitHub issue