XSockets Client Connecting But Not Receiving Messages

596 Views Asked by At

I'm trying to set up a specific scenario but, obviously, I'm having problems. My server is a site that primarily hosts a WCF service but I want to add an XSockets host there as well. I have the standard code in the bootstrap code file as per the instructions in the readme.txt. Upon a client connection, I am starting a worker thread which is basically a heartbeat that the client will monitor. The relevant code from the controller is as follows:

public class HeartbeatController : XSocketController
{
    public void AddMessage(string message)
    {
        this.SendToAll(message, "addMessage");
    }
}

Within my worker thread I am calling this:

string message = String.Format("pump", Math.Round(cpuCounter.NextValue());
ClientPool connection = ClientPool.GetInstance("ws://mywebsite:4502/HeartbeatController", "*");
connection.Send(message, "addMessage");

Currently I'm testing this with a console client which looks like this:

class Program
{
    static XSocketClient socketClient;

    static void Main(string[] args)
    {
        Console.WriteLine("Starting client...");

        string url = "ws://mywebsite:4502/HeartbeatController";

        socketClient = new XSocketClient(url, "*");
        socketClient.OnOpen += socketClient_OnOpen;
        socketClient.Open();

        while (true)
        {
            // let it sit and display the "pump" messages
            string input = Console.ReadLine();

            if (input.Equals("Q", StringComparison.Ordinal))
            {
                break;
            }
        }
    }

    static void socketClient_OnOpen(object sender, EventArgs e)
    {
        Console.WriteLine("socketClient Opened");
        socketClient.Bind("addMessage", OnAddMessage);
    }

    private static void OnAddMessage(ITextArgs textArgs)
    {
        Console.WriteLine("AddMessage :: {0}", textArgs.data);
    }
}

On the client, if I put a breakpoint in the socketClient_OnOpen method it gets hit so I think it is connecting. But the pump message never makes it to the client.

Two Questions:

  1. Is there anything obvious that I'm missing?
  2. (Unrelated) Since many enterprises really don't like punching holes in their firewalls, is there any way to use port 80 with this setup (so that the client connection would look like "ws://mywebsite/HeartbeatController")?

Thanks for any help!

1

There are 1 best solutions below

3
On BEST ANSWER

So to see what your pump actually was sending in to the server I added a custom pipeline.

public class MyPipeline : XSocketPipeline
{
    //Incomming textmessage
    public override void OnMessage(IXSocketController controller, ITextArgs e)
    {
        Console.WriteLine("IN " + e.data);
        //Let the message continue into the server
        base.OnMessage(controller, e);
    }

    //Outgoing textmessage
    public override ITextArgs OnSend(IXSocketProtocol protocol, ITextArgs e)
    {
        Console.WriteLine("OUT " + e.data);
        return base.OnSend(protocol, e);
    }        
}

Since I then saw that you was sending in a string that actually did not have a property named "message". The actionmethod "AddMessage" expects you to pass in a property message of type string. So you can solve this in two ways, both of them are simple.

  1. Just replace the string parameter in the AddMessage with ITextArgs

    public void AddMessage(ITextArgs message)
    

    or...

  2. Pass in a object from your worker thread instead of a string like this

    connection.Send(new {message}, "addMessage");
    

So all you need to do to get it to work is to change this row

connection.Send(message, "addMessage");

with this row

connection.Send(new {message}, "addMessage");

EDIT: Btw, 4.0 is on the way and the client will be very much improved as well as the serverside stuff.