Showing results for 
Search instead for 
Did you mean: 

How do I get my java program to listen for data FROM a q server?

New Contributor
I'm making an abstract gui in java that listens on a given port for a message from a server that contains data to create a gui with, and then renders it.

I have a q file which is loaded on the instance which sets a handle on the current port, and functions to start the gui application and send messages to it so a gui can be shown.

Currently, the file (name kge.q) consists of:

$[1024i > (value "\\p"); value "\\p 5000i";']; /sets the default port if there isn't one set

.g.h:: .z.w;

system("java -jar $QHOME/gui/gui.jar ", string value "\\p");

//sends an update message with the data and the name when a variable is changed
.z.vs: {[v;i]
    a: value v;
    s: (`update;v;i;a);
    (.g.h) t;

//gShow requires name of working dictionary as **SYMBOL**, not the actual value
gShow: {[dict;title]
    s: (`show; dict; value dict; g dict;title); //g.dict contains the gui description for the data in dict

But the problem I'm having is with figuring out how the java program should listen for the messages. The current function looks like this:

public class Main{

    public Main(int port) {
        final c conn;
        System.out.println("Starting Main...");
        try {
            Object o;
            conn = new c("localhost", port);
            while (true) {
                System.out.println("Reading... ");
                if ((o = conn.k()) != null) {
        } catch (c.KException e) {
            System.exit(1); //couldn't connect to the port
        } catch (IOException e) {

    private void readData(Object k){
        //starts creating the gui here

    public static void main(String[] args) {
        if (args.length > 0) try {
            new Main(Integer.parseInt(args[0]));
        } catch (NumberFormatException e){
            new Main(5000);          //default port
        } else System.exit(1);

Note that this is only the skeleton of the project. There's a lot more to it, this is just the part that it's getting stuck at.

Running in IntelliJ get's as far as printing out "Reading..." once from the main loop, and sending messages using gShow or triggering .z.vs doesn't seem to be working.
In fact, the handle .g.h seems to be at 0i, even though I started q with the command -p 5000.

If I'm doing something wrong or if anyone has a fix for this, the help would be greatly appreciated, thanks.


New Contributor
edit:  gShow also has (.g.h) s

New Contributor

We implement the q as a data publsher,� by reusing u.q to manage the subscribing clients,

The java subscribes to it via .u.sub and q publishes to all subscribers with


ok that's interesting. Is there documentation for this on Q for mortals at all? I don't think I've seen it before...