XSockets and Asp.Net 4.0 Website Project

Can anybody give me a working example of an ASP dot net 4.0 website project that has a working implementation of XSockets in it?

I have set up a blank solution and can connect to ws://localhost:4502/Generic fine, but I cannot connect to a custom controller added to the App_Code folder.

I am using the latest XSockets, installed via nuget today (13 Jan 2014).

When trying to connect to the custom controller I get an XSocketException "The handler name was not found in loaded plugins".

The custom controller code is I file called MyTestController.cs, and in App_Code folder. I have been trying to get it to work for 4-5 hours, with no luck. I cannot find any documentation that says I need to register the new controllers manually in the RegisterRoutes call.

I have tried to create an MVC app to see what adding XSockets does to it but this did not manually register any routes.

Using a Web Application or an MVC application is not possible as we need to try to implement this into a very big and mature legacy website.

The custom controller is as follows:

 using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Threading;
using System.Web;

using XSockets.Core.Common.Socket.Event.Interface;
using XSockets.Core.XSocket;
using XSockets.Core.XSocket.Helpers;


/// <summary>
/// Summary description for TestController
/// </summary>
/// 
namespace XSocketsTest1
{ 

    public class MyTestController: XSocketController
    {
        public MyTestController()
        {
            Debug.Print("TestController Created");
            this.OnOpen += TestController_OnOpen;
            this.OnClose += TestController_OnClose;
        }

        void TestController_OnClose(object sender, XSockets.Core.Common.Socket.Event.Arguments.OnClientDisconnectArgs e)
        {
            Debug.Print("TestController_OnClose");
            //throw new NotImplementedException();
        }

        void TestController_OnOpen(object sender, XSockets.Core.Common.Socket.Event.Arguments.OnClientConnectArgs e)
        {
            Debug.Print("TestController_OnOpen");
            this.Send("Hello there. You have connected.", "msgClient");
        }   

        void RunReport()
        {
            Debug.Print("RunReport");
            this.Send("You called RunReport", "msgClient");
        }
    }
}

Default.aspx is here:

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

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <h1>Clean Page - XSockets In Web Site Project Tester</h1>
        <p>This is to prototype xsockets in a web site project.</p>
        <p>Target environment needs to be .net 4.0 Web Site project, and <em>cannot be a web application</em>.</p>

        <h4>Results</h4>
        <div class="js-log-contents log-contents">
        </div>

    </div>
    </form>

    <style type="text/css">
        .log-contents{border:2px solid grey;min-height:200px; width:400px;}
        .log-contents.success{border-color:#0f0;}
        .log-contents.error{border-color:#f00;}
        em{font-weight:bolder;}
    </style>
    <script src="Scripts/jquery-2.0.3.min.js"></script>
    <script src="Scripts/XSockets.latest.js"></script>
    <script src="Scripts/XSockets.fallback.latest.js"></script>
    <script type="text/javascript">
        var page =
            {
                self: this,
                config: {
                    //controllerAddress: "ws://localhost:4502/MyTest"                                                //  Does Not Work
                    controllerAddress: "ws://localhost:4502/MyTestController"                              //  Does Not Work
                    //controllerAddress: "ws://localhost:4502/XSocketsTest1.MyTest"                      //  Does Not Work
                    //controllerAddress: "ws://localhost:4502/XSocketsTest1.MyTestController"   //  Does Not Work
                    //controllerAddress: "ws://localhost:4502/Generic"                                               //  Works
                },

                logger:
                {
                    logIdentifier: "js-log-contents",
                    failCssClass: "error",
                    successCssClass: "success",
                    fail: function (msg) { $("." + this.logIdentifier).append(msg).removeClass(this.successCssClass).addClass(this.failCssClass); },
                    success: function (msg) { $("." + this.logIdentifier).append(msg).removeClass(this.failCssClass).addClass(this.successCssClass); }
                }
            };


    //  XSockets client code - copied from xsockets.net.
        var conn;
        var controllerAddress = page.config.controllerAddress;
        conn = new XSockets.WebSocket(controllerAddress);

        conn.on(XSockets.Events.open, function (clientInfo) {
            console.log("Open successful, controller name is " + controllerAddress, clientInfo)
            page.logger.success("Successfully opened " + controllerAddress);
        });

        conn.on(XSockets.Events.onError, function (err) {
            console.log('Error, controller name is ' + controllerAddress, err);
            page.logger.fail("Failed to open " + controllerAddress);
        });

        $(function () {
        });
    </script>
</body>
</html>

Answers


When you add classes to the App_Code folder they will be marked by visual studio with "build action = content" instead of "build action = compile" If you want to have your controllers inside of App_Code just right click the file and choose properties, then change build action to compile instead of content.

Although XSockets has a MVC pattern it has nothing to do with ASP.NET MVC, so you will not see any routes. XSockets is built to be stand-alone and does not depend on IIS, Apache etc.

Since your class (controller) under App_Code does not compile XSockets will not find it on startup. If you cant change to "build action" = compile for some reason, then add a class library where you install XSockets.Core and build your controllers. Then you can reference this lib in the project where you start the XSockets server. It will now be found by XSockets.

Btw. I see that you send a "msgClient" event when a client connects, but I do not see any subscriptions for that topic in your javascript.


Did anyone figure out how to change build action or do "add a class library where you install XSockets.Core and build your controllers. Then you can reference this lib in the project where you start the XSockets server. It will now be found by XSockets." that..

As far as I can tell you can't change the build action of a file in asp.net web pages projects and I'm not even remotely sure how to add a class library to install XSockets.Core and build controllers.. xD


Need Your Help

Run a javascript when a button is clicked

javascript android android-webview

I have a button underneath a WebView. When I click on it I want a javascript of run on the WebView.

Why embedded CRC and current CRC differs?

delphi delphi-xe5 crc32

I have found this Delphi examle. It is supposed to embed CRC and check current CRC. Both should match, but I get different results. How to fix it? And how to speed it up?