Hosting - XSockets/XSockets.NET-4.0 GitHub Wiki
##Hosting ###OWIN Note: Requires .NET 4.5+ To host XSockets in OWIN is easy and also let you access the HttpContext and the authenticated user (if any).
Install
PM> Install-Package XSockets.Owin.Host
Register XSockets in Owin IAppBuilder
//using XSockets.Owin.Host;
public class Startup
{
public void Configuration(IAppBuilder app)
{
app.UseXSockets(true);
}
}
###Windows Service [Deprecated] Use the XSockets.Windows.Service package from chocolatey to install XSockets as a windows service. You can then add you custom configurations, controller, interceptors etc into the location of the service and restart it to make it find you custom code.
Note that by default you will get the Generic
controller as well as the WebRTC
controller named "Broker" installed with the service.
Install:
- If not done install chocolatey (http://chocolatey.org/)
- Open up the Command Prompt and type cinst XSockets.Windows.Service
###Console Application Create a new ConsoleApplication and install the package XSockets. This will output some sample code for getting the server started.
Install:
PM> Install-package XSockets
//using XSockets.Core.Common.Socket;
//using XSockets.Plugin.Framework;
using (var container = XSockets.Plugin.Framework.Composable.GetExport<IXSocketServerContainer>())
{
container.Start();
foreach(var server in container.Servers)
{
Console.WriteLine(server.ConfigurationSetting.Endpoint);
}
Console.WriteLine("Server started, hit enter to quit");
Console.ReadLine();
}
###Azure You will have to have the Azure SDK installed.
-
Create a Windows Azure Worker Role
-
Open the Package Manager Console
-
Install the XSockets.Server using
PM -> Install-Package XSockets.Server
-
Open the Property Page for the Worker Role. You will find it in the /Roles/ foler of your WorkerRole Project.
-
Add a TCP endpoint using the Endpoints Tab.
- Name the Endpoint i.e 'MyEndoint'
- Set the type to input
- Set the protocol, to TCP
- Define the Public & Private port that you want to use.
-
Add a configuration setting using the Settings tab, we need to define the EndPoint Uri here.
- Set a name on the setting i.e 'MyUri'
- Set the type to string
- Set the value to i.e
ws://127.0.0.1:4510
(this depends on your enviorment).
-
Add the following code the the OnStart() method of your WorkerRole (WorkerRole.cs)
var container = XSockets.Plugin.Framework.Composable.GetExport<IXSocketServerContainer>(); // Create a Custom Configuration based on what we have defined using property pages. var myCustomConfig = new List<IConfigurationSetting>(); var config = new ConfigurationSetting(new Uri(RoleEnvironment.GetConfigurationSettingValue("MyUri"))) { Endpoint = RoleEnvironment.CurrentRoleInstance.InstanceEndpoints.FirstOrDefault(n => n.Key.Equals("MyEndpoint")) .Value.IPEndpoint }; myCustomConfig.Add(config); container.Start(configurationSetting: myCustomConfig);
-
Compile and run
Now, Try connect to the Generic Controller using the following piece of JavaScript Code
var ws = new XSockets.WebSocket('ws://127.0.0.1:4510',['generic']);
###Amazon
TBD