Serialization error on client connecting to socket server

55 views
Skip to first unread message

Frank Richardson

unread,
May 22, 2015, 9:19:11 AM5/22/15
to xsocke...@googlegroups.com
Hi.

I am experiencing an interesting error.

I made a simple xsocket client and server; all works 100% on my local desktop computer.  But then I run the socket server from our development server, and try to connect my client, I receive the following error:

 [Error] Could not read frame "{\"Blob\":null,\"Data\":\"{\\"
Init\\":true}\",\"MessageType\":0,\"Controller\":\"broadcast\",\"Topic\":\"0xcc\
"}"
System.NullReferenceException: Object reference not set to an instance of an obj
ect.
   at XSockets.Core.XSocket.Model.Message..ctor(IList`1 blob, MessageType messag
eType, IXSocketJsonSerializer serializer, String controller)
   at XSockets.Protocol.XSocketProtocol.OnIncomingFrame(IList`1 payload, Message
Type messageType)
   at XSockets.Protocol.XSocketProtocol.<SetFrameHandler>b__b(IList`1 payload, F
rameType op)

I have checked the firewalls, and the traffic is correctly passing through to the server.

Using WireShark, I inspected the data packets, and noticed a difference between the data on a successful call vs a failed call. (Screen shot attached)  Good = successful call; Bad = error as above

It seems as though 2 different types of serialization are been applied, but this is all internal to xsockets.

Can anyone please shed some light as we have just recently purchased a license?

Regards
Frank

Capture.PNG

Ulf Björklund

unread,
May 22, 2015, 9:32:39 AM5/22/15
to xsocke...@googlegroups.com
Hi Frank

I have never seen this myself, but we do have one customer that has reported this kind of error... but they did provide any frames with differences as you have. Thanks for that!
It would be very helpful if you could specify the following

- Server version
- Client version and type of client
- Version of Newtonsoft.JSON

Regards
Uffe

Frank Richardson

unread,
May 25, 2015, 9:26:03 AM5/25/15
to xsocke...@googlegroups.com
Thanks for the reply.

- Server version : 4.2.0 (Simple console application)
- Client version and type of client : 4.2.0 (Simple console application)
- Version of Newtonsoft.JSON : 6.0.8

- Desktop computer : Windows 7 SP1
- Server : Microsoft Windows Server 2008 Standard SP2

I have also downloaded the xsocket sample applications and get the same error across the board.

Regards
Frank

Ulf Björklund

unread,
May 26, 2015, 8:29:13 AM5/26/15
to xsocke...@googlegroups.com
Hi Frank

This have to have something with serialization to do...
If you in your client write this...

var c = new XSocketClient("ws://localhost:4502", "http://localhost", "generic");
var json = c.Serializer.SerializeToString(new Message(new {init = true}, "0xcc", "broadcast"));

What do yo u see?

You should see 
{"B":null,"D":"{\"init\":true}","C":"broadcast","T":"0xcc"}

Regards
Uffe

Ulf Björklund

unread,
May 26, 2015, 8:33:40 AM5/26/15
to xsocke...@googlegroups.com
Another question just to be sure...

Do you use your desktop machine to connect to the 2008 server when the issues occur? Or is the client on another machine?

Regards
Uffe

Frank Richardson

unread,
May 26, 2015, 8:44:40 AM5/26/15
to xsocke...@googlegroups.com
When running the code you've provided, the resultant json is : {"Blob":null,"Data":"{\"init\":true}","MessageType":0,"Controller":"broadcast","Topic":"0xcc"}

Yes, when desktop to server, error occurs. 

If I host the xsocket server on my desktop, the client (also running on my desktop) connects successfully.

Also, if I use the client on another 2008 server, and connect that to a xsocket server hosted on another 2008 server; everything connects successfully.

Our IT dept have also confirmed that the traffic is allowed from desktop to server.

Regards
Frank

Ulf Björklund

unread,
May 26, 2015, 8:50:26 AM5/26/15
to xsocke...@googlegroups.com
Hi Frank

So this tells us that the Newtonsoft serializer fails on your Win7 SP1 machine but is ok on the server...
Will try to write you a custom serializer so that you can try again.
Unfortunatelly I have no access to a win7 machine right now...

Will get back to you as soon as I know anything.

Regards
Uffe

Frank Richardson

unread,
May 26, 2015, 9:02:46 AM5/26/15
to xsocke...@googlegroups.com
It does seem to indicate this; however, if I host the xsocket server on my Win7 machine, and I also run the xsocket client on the same machine, it works perfectly.

Ulf Björklund

unread,
May 26, 2015, 9:05:09 AM5/26/15
to xsocke...@googlegroups.com
Any chance you can send me your sample project so that I can investigate further?

Regards
Uffe

Ulf Björklund

unread,
May 26, 2015, 9:17:21 AM5/26/15
to xsocke...@googlegroups.com
If it works locally that is probably due to the fact that serialization fails in both client and server, therefor the server does not expect packages with DataMember names shortened to "C" for "Controller", "T" for "Topic" and so on...
If you use wireshark again on your local machine I expect that the JSON will be with full property names.

So I have to find out why your machines does not serialize the way Newtonsoft.JSON should do...

Regards
Uffe

Ulf Björklund

unread,
May 26, 2015, 9:37:58 AM5/26/15
to xsocke...@googlegroups.com
Hi again Frank

Since I cant reproduce the error it is also hard to know when I have solved the issue :)
Can you try to add the "System.Runtime.Serialization" assembly to your client project and see if things improve?

Regards
Uffe

Frank Richardson

unread,
May 26, 2015, 10:24:15 AM5/26/15
to xsocke...@googlegroups.com
I have added the System.Runtime.Serialization, but get the same error.

If possible, can you please send me the source code, so that we can debug? 

Below is the problem child code; it's basically your stock ticker demo:

Server code:

namespace StockServer
{
    internal class Program
    {
        private static void Main(string[] args)
        {
            var container = XSockets.Plugin.Framework.Composable.GetExport<IXSocketServerContainer>();
            var config = new List<IConfigurationSetting> { new ConfigurationSetting(new Uri("ws://localhost:4042"), new Uri("ws://localhost:4042")) };
            container.Start(configurationSettings: config);

            Console.ReadLine();
        }
    }

    public static class XSocketsBootstrap
    {
        private static IXSocketServerContainer container;

        public static void Start()
        {
            container = XSockets.Plugin.Framework.Composable.GetExport<IXSocketServerContainer>();
            container.Start();
        }
    }
}

Client Code:
namespace StockClient
{
    class Program
    {
        static void Main(string[] args)
        {
            var c = new XSocketClient("ws://localhost:4042", "http://localhost", "stock")
            {
                AutoReconnect = true
            };

            c.OnConnected += (sender, eventArgs) => Console.WriteLine("CONNECTED");

            c.Open();

            c.Controller("stock").Subscribe("tick", s =>
            {
                Console.WriteLine("Tisk");
            });

            Console.ReadLine();
        }
    }
}


Ulf Björklund

unread,
May 26, 2015, 10:45:49 AM5/26/15
to xsocke...@googlegroups.com
Sure, that is the best option since I cant reproduce this.


Regards
Uffe

Ulf Björklund

unread,
May 26, 2015, 2:58:34 PM5/26/15
to xsocke...@googlegroups.com
Hi again

Just created a new Console application to provide you with a simple test

using System;
using System.Runtime.Serialization;

namespace JsonTest
{
    [DataContract]
    public class Foo
    {
        [DataMember(Name = "A")]
        public string ALongName { get; set; }
        [DataMember(Name = "B")]
        public string BLongName { get; set; }

        public string NotSerialized { get; set; }
    }

    class Program
    {
        static void Main(string[] args)
        {
            var a = new Foo()
            {
                ALongName = "AAAA",
                BLongName = "BBBB",
                NotSerialized = "CCCC"
            };
            var json = Newtonsoft.Json.JsonConvert.SerializeObject(a);

            Console.WriteLine(json);

            //OUTPUT: {"A":"AAAA","B":"BBBB"}
            Console.ReadLine();
        }
    }
}


If the output from this is anything but 
{"A":"AAAA","B":"BBBB"}
You have an issue with Newtonsoft.JSON on your machines.

Regards
Uffe


Janus C. H. Knudsen

unread,
Jul 21, 2016, 6:48:32 PM7/21/16
to XSockets.NET Developer forum
Hello

I was just trying to setup Wireshark for tracing XSockets as well, but couldn't get it to work.

I installed the Microsoft Loopback Adapter.

Any hints ?

Cheers
Janus

Ulf Björklund

unread,
Jul 22, 2016, 3:08:04 AM7/22/16
to XSockets.NET Developer forum
Hi Janus

Since you are writing in the thread I assume that you have some serialization issue?
Is it with the 3.5 client?

Can you provide a sample repository so that we can test/reproduce?

Regards, Uffe

Janus C. H. Knudsen

unread,
Jul 22, 2016, 5:08:47 PM7/22/16
to XSockets.NET Developer forum
At first I tried with a setup between a server and Unity3D, 3.5 client, but then I switched to the provided StockTicker sample, unfortunately without any change. I should mention that I've never used Wireshark before on localhost, so I'm a bit novice setting it up. I've probably done something wrong so please be gentle, should I change anything in the sample localhost:port 

I installed Microsoft Loopback Adapter and followed these steps:
1. go to MS Loopback adapter properties, set IP 10.0.0.10, MASK 255.255.255.0
2. ipconfig /all and look at the MAC-ID for your new adapter.
3. arp -s 10.0.0.10 <MAC-ID>
4. route add 10.0.0.10 10.0.0.10 mask 255.255.255.255
5. to test: "telnet 10.0.0.10"

Ulf Björklund

unread,
Jul 25, 2016, 4:09:16 AM7/25/16
to XSockets.NET Developer forum
Hi Janus

I am no Wireshark expert, but what is the problem that you have with XSockets and the .NET 3.5 client?
I can (try to) help you with that if I know the issue.

Regards, Uffe

Janus C. H. Knudsen

unread,
Jul 26, 2016, 5:14:32 AM7/26/16
to XSockets.NET Developer forum
Hi Uffe

You are always so helpful.
I kind of high jacked this thread, cause I read that the poster was working with Wireshark, not that I experienced the same problem.

During my analysis of socket communication on localhost I just wanted to trace the payload and packet size.

I couldn't get Wireshark to work, but I'm experiencing problems with some of my network adapters on my machine, I guess I need to do a reinstall.

Don't waste more time on me :), I will get back when I have something more specific.
 

Reply all
Reply to author
Forward
0 new messages