Responding to q requests from C#

Hi,

I’m trying to write a simple C# program that holds some state and responses to q requests. But I cannot figure out a proper way to write the response code.

Below is a simple POC program that I have right now:

namespace POC

{

class Program

{

static object data = new object

{

“hello”,

(Int32)1234,

“world”

};


static void Main(string args)

{

c c = new c(“localhost”, “11111”);

while (true)

{

object cmd = c.k();

if (cmd is String)

{

String req = (String)cmd;

if (req.Length > 0)

{

switch (req[0])

{

case “getData”:

c.k(data); // This crashes within c!

c.ks(data); // This is invalid, as c.ks expects the first argument to be a string!

// How do I return `data’ to q?!

break;

default:

break;

}

}

}

}

}

}

}

The above code is based on the code in the “Simple subscriber” section of “C# client for kdb+” document. But the sample code provided is for a “pure” subscriber, i.e., C# is not supposed to reply to data published from q. In my case, however, I need to respond to requests from q – How to I send the response?

Answering my own question…

It appears this is a missing feature in c.cs.

In short, c.k calls w(1,x) whereas c.ks calls w(0,x), corresponding to sync and async messages, respectively (http://code.kx.com/wiki/Reference/ipcprotocol#serializing\_an\_integer\_of\_value\_1).

But to send a response message, I need w(2,x), which is not supported by c.cs – w(int,object) is not public.

Looks like I’ll have to hack c.cs for now in order to support the usage case I have now.