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>