Jycraft / jycraft

Extend Minecraft servers with Python using Jython.
BSD 3-Clause "New" or "Revised" License
13 stars 2 forks source link

Interpreter results sent over websocket one character at a time #2

Closed pauleveritt closed 8 years ago

pauleveritt commented 8 years ago

When using the existing jycraft-web websocket client (and my Angular websocket client), if I send over something to be evaluated after login, the results get received one character at a time.

That is, if I do:

print 'abcdef'

...in the ACE editor and console.debug the .onMessage handler, I see that each character in the string is a different onMessage event.

Here is, I believe, the relevant code snippet:

    final InteractiveInterpreter interpreter = connections.get(ws);
    boolean more = false;
    try {
        if (message.contains("\n")) {
            more = parse(interpreter, message, true);
        } else {
            buffers.put(ws, buffers.get(ws)+"\n"+message); 
            more = parse(interpreter, buffers.get(ws), false);
        }
    } catch (Exception e) {
        ws.send(e.toString()+"\n");
    }
    if (!more) buffers.put(ws, "");
    if (more) ws.send("... ");
    else ws.send(">>> ");
Macuyiko commented 8 years ago

Should now be improved thanks to buffering the outputstream in the interpreters, see commit c007350dc5f2532b023609a49aa8d17b2f2aedb3

pauleveritt commented 8 years ago

Great, thanks for working on this!

Is it ok if I file some tickets for a couple of other things, or should I wait and let you do what you have in mind?

—Paul

On Aug 10, 2015, at 10:31 AM, Seppe vanden Broucke notifications@github.com wrote:

Should now be improved thanks to buffering the outputstream in the interpreters, see commit c007350 https://github.com/Jycraft/jycraft-server-plugin/commit/c007350dc5f2532b023609a49aa8d17b2f2aedb3 — Reply to this email directly or view it on GitHub https://github.com/Jycraft/jycraft-server-plugin/issues/2#issuecomment-129475023.

Macuyiko commented 8 years ago

Go for it, this is a good way for me to work on/keep track of things!