XSockets.NET TeamBlog

News, updates and other information from Team XSockets.NET

Here Team XSockets provide the latest information about the framework.
You will also find videos and stuff produced by us (and others).

If you have done something with XSockets.NET, tell us and we might post about it here!

 

Meet Faiz from 10pearls

Wednesday, February 25, 2015 12:34 PM 0

From time to time we interview some of our users to learn more about what people like about XSockets.NET, but ofcourse aso to learn about what we can improve. In this interview we talked with Faiz ul Haque from Karachi, Pakistan.


Meet Faiz ul Haque a astute person from Karachi, Pakistan.
He is working as a senior software engineer at http://10pearls.com. A company, specializing in Mobile Applications, Enterprise Software, Web, and Gamification.

About 10pearls:
Founded in 2004, the management of 10Pearls has the experience, expertise, and passion to succeed. The management has managed highly scalable technology projects and implementations across Fortune 500 companies and start-up ventures, including: AOL, Time Warner, NVR, Spacenet, MicroStrategy, Paxfire, and the Asian Pacific Institute of Technology. The principals of the company are committed to innovation, and helping solve customer challenges through out-of-the-box thinking and disciplined, rapid execution.


XSockets:
Great that you take your time answering a few questions. First of all tell us more about your self? We are very curious about the person, who is Faiz
Faiz:
:) always feel in unusual position when describing my self, well i am self motivated, love to learn new tech, team player. worked on many technologies like .net, nodejs, android, python, js frameworks (angular, ember, knockout, etc) etc. Mostly spend my free time (obviously) development of two player games. Smart and optimized code is the thing i like most.

XSockets:
Where did you first hear about XSockets.NET?
Faiz:
well the answer is google of course, :),
In mid of 2013 i guess, i have on some of project involving real time data transfer, so i start digging to find out can we transfer video stream same like skype doing, so found the webrtc and XSocket.NET

XSockets:
What did you find (most) interesting at the first look at XSockets.NET?
Faiz:
Frankly the implementation or integration with existing application is damn easy peasy like eating cake. Especially the WebRTC part (either self hosted or other).

XSockets:
Did you compare us to other frameworks?
Faiz:
Ya, i did, well it’s not actually a comparison thing, as i said, i found XSocket.NET while Googling, found other too like apprtc, easyrtc some other too, but i could say frankly Xsockets implementation of Webrtc is always on my priority first.

XSockets:
Okey, so you compared us with others? What made you choose XSockets.NET?
Faiz:
The implementation or integration part, it’s feel like plug and play.

XSockets:
Were there more people involved in the development process, or did you work alone?
Faiz:
I am alone in this particular project.

XSockets:
What components of XSockets did you use?
Faiz:
Mostly Webrtc.

XSockets:
So, what was (and is) the best thing with XSockets?
Faiz:
well, Xsockets is pretty straight forward, simple in integration and implementation. Just inherit the actual class (like ConfigurationSetting) to extend or override as per you need, that what i like most.

XSockets:
What problems did you encounter along the way?
Faiz:
Mostly with SSL implementation, but i don’t want to mention it as problem .

XSockets:
How did the Team of XSockets.NET help you out? What is your thoughts about our support? Be frank!
Faiz:
Documentation and guide are already available, so i didn’t required to contact any Xsockets team members, so i can’t say anything on that point.

XSockets:
In addition to what you just said what can we do differently?
Faiz:
I think, you guys should start PaaS for XSocket features.

XSockets:
When XSockets.NET went from being free to not free, what were your thoughts?
Faiz:
Well, i am still using developer license (free), i like open Source stuff, but unfortunately you guys did really hard work to code it and also maintain it. so would say it’s OK for me.

XSockets:
What where the main programming challanges when using XSockets.NET?
Faiz:
Well i didn’t find any challenges expect configuration of SSL/TLS.

XSockets:
Is there any particular use-case, scenarios where you can see that XSockets.NET would be perfect to use?
Faiz:
As i said, i mostly utilize the WebRTC feature of XSockets, i utilized it in to make conference call between doctor and patient. So i believe telemedicine would be perfect scenario.

XSockets:
Do you plan to use XSockets.NET again? Maybe you have used it several time already?
Faiz:
Basically it’s depends on work, but i would if i got the opportunity.

XSockets:
Would you recommend others to use XSockets.NET?
Faiz:
My dev circle knowns XSockets.NET via me.

XSockets:
Oki doki, thanks for answering our questions, is there something else on your mind that you feel to share?
Faiz:
Just one thing for other developers , if you guys need some thing real time just plugin with XSockets.NET.

XSockets:
Thank you very much!
Faiz:
Thanks

unsigned vs signed assemblies, happy to not care!

Friday, April 25, 2014 9:45 AM 0

The topic “signed vs unsigned assemblies” has become a hot topic in the .NET community, and today I saw a tweet where Itamar Syn-Hershko (@synhershko) said:

I’ve had enough. I’m moving to removing strong-naming aka signed assemblies from #Lucene.net http://permalink.gmane.org/gmane.comp.jakarta.lucene.net.devel/6615 #dotnet

So I read the post, and I actually don not have a opinion about “Strongly Named Assemblies”… That might seem strange since it seems to be a hot topic. Guessing that it is a hot topic since peoples (developers) are having trouble with it (doh).

So why don´t I have any opinion about this?
Because I do not have a problem with assemblies (signed or not).

I spend most of my time as a developer on the XSockets.NET team, and almost all our assemblies are signed. But we use ServiceStack.Text (which is awesome by the way) that is unsigned! How?

 

Using unsigned assemblies in signed assemblies

You cant reference an unsigned assembly in signed assembly, but how can we use unsigned assemblies all over XSockets.NET even though XSockets.NET is signed?

Let us look at how we use the unsigned ServiceStack.Text inside of the signed XSockets.NET.

Have the interface in a signed assembly

Inside of the signed assembly XSockets.Core.Common.dll there is a interface for serialization.

using System;
using System.Collections.Generic;
using XSockets.Plugin.Framework;
using XSockets.Plugin.Framework.Attributes;
namespace XSockets.Core.Common.Utility.Serialization
{
    //Will export this interface... This is optional, can done at runtime.
    //but it will be replaced if another implementation is found
    [Export(typeof(IXSocketJsonSerializer), null, Rewritable.Yes)]
    public interface IXSocketJsonSerializer
    {
        //Serialization
        string SerializeToString<T>(T obj);
        string SerializeToString(object obj, Type type);
        //Deserialization
        T DeserializeFromString<T>(string json);
        object DeserializeFromString(string json, Type type);
        IDictionary<string, string> DeserializeFromString(string json, params string[] keys);
    }    
}

Have the implementation in a unsigned assembly

Inside of the unsigned assembly XSockets.Serialization.dll we have a reference to ServiceStack.Text and we implement the interface found in the signed assembly XSockets.Core.Common.dll (described above)

using System;
using System.Collections.Generic;
using System.Linq;
using ServiceStack.Text;
using XSockets.Core.Common.Utility.Serialization;
namespace XSockets.Serialization
{
    /// <summary>
    /// The default plugin for serialization
    /// To have your custom serializer implement IXSocketJsonSerializer
    /// </summary>    
    public class XSocketJsonSerializer : IXSocketJsonSerializer
    {
        public XSocketJsonSerializer()
        {
            JsConfig.ExcludeTypeInfo = true;
        }
        public string SerializeToString<T>(T obj)
        {
            return JsonSerializer.SerializeToString(obj);            
        }
        public string SerializeToString(object obj, Type type)
        {
            return JsonSerializer.SerializeToString(obj, type);
        }
        public T DeserializeFromString<T>(string json)
        {
            return JsonSerializer.DeserializeFromString<T>(json);
        }
        public object DeserializeFromString(string json, Type type)
        {           
            return JsonSerializer.DeserializeFromString(json, type);
        }
        public IDictionary<string,string> DeserializeFromString(string json, params string[] keys)
        {
            var obj = JsonSerializer.DeserializeFromString<List<JsonObject>>(@json);
            return keys.ToDictionary(key => key, key => obj[0].Child(key));
        }
    }    
}

Have the usaged in a signed assembly

So we had an interface in a signed assembly, the implementation in a unsigned assembly since we wanted to use ServiceStack.Text (unsigned). Now we need to get the instance in a signed assembly.

The XSockets.Plugin.Framework will help us…
There are several ways of getting an instance of the JsonSerializer.

  1. Get the instance from the plugin framework directly.

    var serializer = Composable.GetExport<IXSocketJsonSerializer>();
    
    
  2. Mark a property with the [ImportOne] attribute and it will be created when the parent is created.

    [ImportOne(typeof(IXSocketJsonSerializer))]
    public IXSocketJsonSerializer JsonSerializer { get; set; }
    
    

Summary

I find the recent discussions about this topic in social media to be very interesting, but it feels great to not have to bother about it. In the best of worlds all assemblies would be either signed or unsigned.

The way we do it probably don’t fit all project since it demands full modularity, but hopefully it will help (or provide an ideas) to someone reading it.

If you are interested in learning more about the plugin framework here is some info

EDIT: When I think about it I would not mind switching XSockets to unsigned since I actually do not care about signing the assemblies, but I guess that some users of XSockets would get upset since they probably sign their assemblies.

Regards
Uffe, Team XSockets

The importance of state in realtime platforms

Wednesday, March 19, 2014 9:13 AM 0

Having state is crucial in real-time platforms. State is what helps us knowing what clients to send to (the subscribers), and state will also help us finding/sending-to a subset of subscribers...

Why is this important?

First of all we should NEVER broadcast data... A client that is not subscribing for a topic should never get a message about it. Second. If you have 1000 subscribers, but you only want to target 5 of them you have to be able to do so. The other 995 clients should NOT get the message and it should be EASY for you to find these 5 client as a subset from the 1000 subscribers.

An example...

Lets say that you have a chat (yeah I know it's always a chat). You have a lot of clients in the chat so you have to filter where to send the messages. To keep things simple we only have Name, City, Status and Hobby as criterias in the chat. So that the client can say "I'm James. A single person in Boston and my hobby is JavaScript".

We will now know the city, status and hobby of all the clients. What you do with this knowledge is up to you, but lets say that we want to send a message to all people having the same profile as the sender. What would that look like?

The controller

public class MyChat : XSocketController
{
    public string Name { get; set; }
    public string City { get; set; }
    public string Status { get; set; }
    public string Hobby { get; set; }

public void OnChatMessage(string message)
    {
        //This is all it takes to target the clients!
        this.SendTo(p => p.City == this.City && p.Status == this.Status && p.Hobby == this.Hobby
        , this.Name + " - " + message, "onChatMessage");
    }
    //Explanation:
    //Above e use the extension SendTo(Func<T,bool>, object o, string topic);
    //First parameters let you filter with intellisense
    //Second is the object to send (anything that can be serialized)
    //Third is the topic (subscription)
}

Thats it... And it is easy to set the properties on the controller from javascript if you do not want to pass them in with the connection (or write a method that handles the get/set stuff).

Bulding a UI for the MyChat controller could in its simplest form look something like:

The everybody is named 'Glen' chat

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <title></title>
    </head>
    <body>
        <h3>The everybody is named 'Glen' chat</h3>
        <select id="cities">
            <option value="New York">New York</option>
            <option value="Boston">Boston</option>
            <option value="Phoenix">Phoenix</option>
        </select><hr />
        <select id="status">
            <option value="Single">Single</option>
            <option value="Relationship">Relationship</option>
        </select><hr />
        <select id="hobby">
            <option value="JavaScript">JavaScript</option>
            <option value="CSharp">CSharp</option>
        </select><hr />
        <input type="text" id="input-message" value="Goo LR" />
        <button id="btn-send">send</button>
        <div id="messages"></div>
    <script src="Scripts/jquery-2.0.3.js"></script>
    <script src="Scripts/XSockets.latest.js"></script>

<script>
        var conn = null;
        $(function () {
            //Create a connection
            conn = new XSockets.WebSocket('ws://localhost:4502/MyChat');
conn.onopen = function () {
                //Connected, set the C# properties (faking for demo purpose)
                conn.publish('set_City', { value: 'New York' });
                conn.publish('set_Hobby', { value: 'JavaScript' });
                conn.publish('set_Status', { value: 'Single' });
                conn.publish('set_Name', { value: 'Glen' });
//Subscribe for onchatmessage, but I will only get messages within the same city, hobby & status
                conn.on('onchatmessage', function (d) {
                    $('#messages').prepend($('<div>').text(d));
                });
            };
//When the button is clicked
            $('#btn-send').on('click', function () {
                conn.publish('onchatmessage', { message: $('#input-message').val() });
            });
            //When city is changed
            $('#cities').on('change', function () {
                conn.publish('set_City', { value: $(this).val() });
            });
            //When status is changed
            $('#status').on('change', function () {
                conn.publish('set_Status', { value: $(this).val() });
            });
            //When hobby is changed
            $('#hobby').on('change', function () {
                conn.publish('set_Hobby', { value: $(this).val() });
            });
        });
    </script>
    </body>
</html>