Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WebSocket4Net simple example fails with "Operation already in progress"

I'm trying to get a simple test going with Xamarin and WebSocket4Net but it fails on Open() with "Operation already in progress". Example code below:

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!");
        }
    }
}

I started with the standard multi-platform project (PCL) and added a button to initiate the connection.

Versions:
0.15.0 WebSocket4Net
0.8.0.13 SuperSocket

The PCL is configured with: .NET Standard Platform = netstandard1.4

I'm fairly new to .NET/Xamarin but have many years of software development behind me.

like image 435
KiwiCodeMonkey Avatar asked Oct 17 '17 11:10

KiwiCodeMonkey


1 Answers

I've got the same issue with 0.15. Have you tried downgrading to 0.14, and removing SuperSocket?

There's a GitHub issue regarding this problem.

Getting this error when trying to connect in StartReceive()

Here's an excerpt:

Excerpt from GitHub issue

like image 77
wonea Avatar answered Nov 06 '22 17:11

wonea