Understanding versions and configurations

47 views
Skip to first unread message

John Rossitter

unread,
Jun 2, 2015, 4:58:43 PM6/2/15
to xsocke...@googlegroups.com
Hi Everyone,

I'm very interested in using XSockets, but I'm struggling to understand some things in the documentation.
First of all, our website is based on a .net 4.5 Website template, so we use Web Forms and app_code folder.
From what I understand, this should not be an issue for XSockets though.

What I'm struggling to understand is how to startup the server properly.
In the written documentation it discusses using the OWIN Startup Attributes and app.UseXSockets
However
In the videos in the academy it discusses using PreApplicationStartupMethod


I have setup my server to use the app.UseXSockets workflow, however I dont know how to determine which ports its running on.
How do I specify/know which ports to use?

Thanks,

John

Ulf Björklund

unread,
Jun 2, 2015, 5:08:47 PM6/2/15
to xsocke...@googlegroups.com
Hi John

XSockets is not specifically about websites, but more about full-duplex communication in general. However, you can ofcourse use XSockets in a website only solution.

I apologize if the documentation is confusing in this area, I will try to explain.

- If you use Owin you can choose to install the XSockets.Owin.Host package... If you do so xsockets will be hosted inside of Owin and the port will be the same as the one Owin uses.
- If you do not use Owin you can startup xsockets with the "PreApplicationStartup" method... 
- You can also host xsockets as a stand alone process to get the best performance... but in development (or if you do not send thousands of msg per second) you can settle for the hosting in the webapp.

If you do not use owin the default port is 4502, but you can add custom configuration by just creating a simple class. http://xsockets.net/docs/4/configuration (see configuration as a plugin)

Let me know if you need more guidance

Regards
Uffe

John Rossitter

unread,
Jun 2, 2015, 5:35:50 PM6/2/15
to xsocke...@googlegroups.com
Hi Ulf,

So in this case would I need to use the installation instructions listed as Self Hosted ?
I tried this and could never get the PreApplicationStartupMethod for fire. I was able to get the Global.Asax OnStart to initialize it, but it kept firing over and over again for some reason.

Thanks,

John

Ulf Björklund

unread,
Jun 3, 2015, 3:18:59 AM6/3/15
to xsocke...@googlegroups.com
Hi John

So, lets see if I can explain this in a proper way.

1: Self hosted
Lets say that you would like to host xsockets stand-alone. This could be anything from hosting it in a windows service, console application or Azure etc...
All you need to do to fire up XSockets the is to get the IXSocketServerContainer from the plugin framework and then start it.

Like this.
using XSockets.Core.Common.Socket;
using XSockets.Plugin.Framework;
using (var container = Composable.GetExport<IXSocketServerContainer>())
{
    container
.Start();
   
Console.ReadLine();
}

2: Hosted in website
Normally our users do not host XSockets inside of a website/webapp since the browser is just one of the clients that they connect to XSockets.
But, if you would like to host XSockets inside the web you have two options. One is to start xsockets as usual, but inside of the web... The other to let Owin host xsockets.

This will cover the hosting outside of owin.
Pre-Req: Install-Package XSockets
using System.Web;
using XSockets.Core.Common.Socket;

[assembly: PreApplicationStartMethod(typeof(HitCounter.Startup), "Start")]
namespace HitCounter
{
   
public static class Startup
   
{
       
private static IXSocketServerContainer container;
       
public static void Start()
       
{
            container
= XSockets.Plugin.Framework.Composable.GetExport<IXSocketServerContainer>();
            container
.Start();
       
}
   
}
}

There is a template for this, so just choose Add->New Item->XSockets 4->XSockets.Web.Bootstrapper

3: Hosted in Owin
You can host XSockets in Owin (stand alone) or in Owin inside of a webapp...

This will cover the hosting in owin in your webapp.
Pre-Req: Install-Package XSockets.Owin.Host
In the Owin Startup class you just add the line app.UseXSockets(); like so...
using Microsoft.Owin;
using Owin;
using XSockets.Owin.Host;

[assembly: OwinStartup(typeof(HitCounter.Startup))]

namespace HitCounter
{
   
public class Startup
   
{
       
public void Configuration(IAppBuilder app)
       
{
            app
.UseXSockets();
       
}
   
}
}

___________________________________
The samples above is taken from the github XSockets Virtual Academy. https://github.com/XSockets/XVA
In there you can see that almost all the samples has one AnyOS folder and one Win8+ folder.
The difference is that the Win8+ ones uses Owin, and the other uses XSockets stand alone.

When you use owin you will connect to the same port as the web... 
So if you web is at http://localhost:12345 you will use ws://localhost:12345 from the JavaScript API
If you self host the default startup port id 4502, but you can change that in a number of ways.
See: http://xsockets.net/docs/4/configuration (personally I prefer configuration as a plugin)

You can ofcourse also host on Azure as mentioned, or anywhere that has .NET 4+ or the Mono equivalent.

Regards
Uffe

John Rossitter

unread,
Jun 3, 2015, 9:09:25 AM6/3/15
to xsocke...@googlegroups.com
Hi Ulf,

Thank You for all of this great information.
I will get to work on using it here shortly.

John
Reply all
Reply to author
Forward
0 new messages