0
votes

I am working on signalr core under asp.net core 2.2.I have mobile as well as web signalr core clients,I have maintained cross domain connection.My web client successgully connnected to signalr core, but my android client gives exception below, "Web sockets are not available on your server", hence , web client is also using web sockets transport layer, and it is in conencting state.

my server side code is in start up class

// This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
{
    services.Configure<CookiePolicyOptions>(options =>
    {
        // This lambda determines whether user consent for non-essential cookies is needed for a given request.
        options.CheckConsentNeeded = context => true;
        options.MinimumSameSitePolicy = SameSiteMode.None;
    });
    services.AddCors(options =>
    {
        options.AddPolicy("CorsPolicy",
            builder => builder.SetIsOriginAllowed((host) => true)/*WithOrigins("https://localhost:44381")*/
            .AllowAnyMethod()
            .AllowAnyHeader()
            .AllowCredentials());
    });
    services.AddSignalR();
    services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2);
}

// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
    if (env.IsDevelopment())
    {
        app.UseDeveloperExceptionPage();
    }
    else
    {
        app.UseExceptionHandler("/Error");
        // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
        app.UseHsts();
    }

    app.UseHttpsRedirection();
    app.UseCors("CorsPolicy");
    app.UseSignalR(routes =>
    {
        routes.MapHub<ChatHub>("/chatHub");
    });
    app.UseMvc();
}

Please , answer me, how i connect android signalr Client to signalr core serever?

1
@O.Jones what does stopwatch frequency have to do with this?kkarakk
@kkarakk oops. working on something else while answering. wrong link. facepalm.O. Jones
Have you looked at this? docs.microsoft.com/en-us/aspnet/core/fundamentals/… (the right link)O. Jones

1 Answers

0
votes

You need to enable WebSockets support on your Server.

To enable WebSockets on Windows Server 2012 or later :

  • Use the Add Roles and Features wizard from the Manage menu or the link in Server Manager.

  • Select Role-based or Feature-based Installation. Select Next.

  • Select the appropriate server (the local server is selected by default). Select Next.

  • Expand Web Server (IIS) in the Roles tree, expand Web Server, and then expand Application Development.

  • Select WebSocket Protocol. Select Next.

  • If additional features aren't needed, select Next.

  • Select Install.

  • When the installation completes, select Close to exit the wizard.