Click here to Skip to main content
15,890,123 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have Created Hub Which is mention below:

C#
class MyChatHub: Hub
{
    public void BroadcastMessageToAll(string message)
    {
        Clients.All.newMessageReceived(message);
    }

    public void JoinAGroup(string group)
    {
        Groups.Add(Context.ConnectionId, group);
    }

    public void RemoveFromAGroup(string group)
    {
        Groups.Remove(Context.ConnectionId, group);
    }

    public void BroadcastToGroup(string message, string group)
    {
        Clients.Group(group).newMessageReceived(message);
    }
}


And Startup.cs File:

C#
using Microsoft.Owin;
using Owin;
[assembly: OwinStartup(typeof(Startup))]
public class Startup
{
    public void Configuration(IAppBuilder app)
    {
        app.MapSignalR();
    }
}


After the creation of Hub And StartUp. I hade made a WebForm trough which ill push messages whch is as follow:

ASP.NET
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title></title>
    <script src="Scripts/jquery-1.6.4.min.js"></script>
    <script src="Scripts/jquery.signalR-2.2.0.min.js"></script>
    <script src="http://localhost:3660/signalr/hubs/" type="text/javascript"></script>
    <script type="text/javascript">
        $(function () {
            console.log('In Functon');
            var myChatHub = $.connection.myChatHub;
            myChatHub.client.newMessageReceived = function (message) {
                $('#ulChatMessages').append('<li>' + message + '</li>');
            }
            $.connection.hub.url = "http://localhost:3660/signalr";
            $.connection.hub.start().done(function () {
                $('#btnSubmit').click(function (e) {
                    myChatHub.server.broadcastMessageToAll($('#txtEnterMessage').val(), 'Web user');
                });
            }).fail(function (error) {
                console.error(error);
            });;

        });
    </script>
</head>
<body>
    <form runat="server">
        <div>
            <label id="lblEnterMessage">Enter Message: </label>
            <input type="text" id="txtEnterMessage" />
            <input type="submit" id="btnSubmit" value="Send Message" />
            <ul id="ulChatMessages"></ul>
        </div>
    </form>
</body>
</html>



I'm Facing some Error in Console which says:
WebSocket connection to 'ws://localhost:3660/signalr/connect?transport=webSockets&clientProtocol=1.5&connectionToken=417dVcVSFQio467G1AKEoT2W9eqpDUBrzGPCJdpcmAggi9hJSO%2BgKgfy%2FB3PVc0OAUXsLZQ%2BciNMG9%2Fw01wOrXdM%2FghOrMaP51qB%2B1tJGNmc%2FkNQqzUgh4vLxgStAATb&connectionData=%5B%7B%22name%22%3A%22mychathub%22%7D%5D&tid=9' failed: Error during WebSocket handshake: net::ERR_CONNECTION_RESET


What I have tried:

Please let me know where I'm going wrong..:(
Posted
Updated 15-Mar-17 0:10am

1 solution

I had the same problem and I fixed it by adding the following code in the Web.config:

<system.Web>
    <httpRuntime targetFramework="4.6" />
</system.Web>
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900