Problem with connecting to WebSocket from ClientWebSocket in Android

209 Views Asked by At

I have written an app to connect to WebSocket via ClientWebSocket. This is the setting of middle ware part in Asp.Net core:

app.Use(async(context,next) =>
{
    if(context.WebSockets.IsWebSocketRequest)
    {
        if(context.Request.Path=="/wschat")
        {
            wsFunctions wsf = new wsFunctions();
            await wsf.ListenAcceptAsync(context);
        }
    }
    else
    {
         await next();
    }
});

And this is the Android side:

private async void btnConnect_OnClick(object sender, EventArgs e)
{
    ClientWebSocket ws = new ClientWebSocket();
    Uri serverUri = new Uri("ws://localhost:55104/wschat");
    var source = new CancellationTokenSource();
    source.CancelAfter(5000);
    await ws.ConnectAsync(serverUri,source.Token);
}

when I click connect button in client side, an error is occur : "Unable to connect to Remote Server."

0

There are 0 best solutions below