webdis icon indicating copy to clipboard operation
webdis copied to clipboard

PUBLISH/SUBSCRIBE doesn't appear to work

Open lamby opened this issue 9 years ago • 2 comments

Terminal 1:

$ curl -v http://127.0.0.1:7379/SUBSCRIBE/test
*   Trying 127.0.0.1...
* Connected to 127.0.0.1 (127.0.0.1) port 7379 (#0)
> GET /SUBSCRIBE/test HTTP/1.1
> Host: 127.0.0.1:7379
> User-Agent: curl/7.50.1
> Accept: */*
> 
< HTTP/1.1 200 OK
< Server: Webdis
< Allow: GET,POST,PUT,OPTIONS
< Access-Control-Allow-Methods: GET,POST,PUT,OPTIONS
< Access-Control-Allow-Origin: *
< Access-Control-Allow-Headers: X-Requested-With, Content-Type
< Content-Type: application/json
< Connection: Keep-Alive
< Transfer-Encoding: chunked
< 

Terminal 2:

$ curl http://127.0.0.1:7379/PUBLISH/test/foo                                                                      
{"PUBLISH":1}

There is no change in terminal 1. I was expecting a {"SUBSCRIBE... line. What am I missing?

lamby avatar Aug 21 '16 17:08 lamby

en,it also can't work with jquery in the example,it use XMLHttpRequest and readyStatus = 3 but jquery seems not support it! the example code is:

var previous_response_length = 0 xhr = new XMLHttpRequest() xhr.open("GET", "http://127.0.0.1:7379/SUBSCRIBE/hello", true); xhr.onreadystatechange = checkData; xhr.send(null);

    function checkData() {
            if(xhr.readyState == 3)  {
                    response = xhr.responseText;
                    chunk = response.slice(previous_response_length);
                    previous_response_length = response.length;
                    console.log(chunk);
            }
    };

yafengabc avatar Aug 28 '16 13:08 yafengabc

but jquery seems not support it!

That would appear to be an entirely separate issue.

lamby avatar Aug 28 '16 14:08 lamby

you need to unbuffer the output: with curl its -N

$ curl -N localhost:7379/SUBSCRIBE/testing
{"SUBSCRIBE":["subscribe","testing",1]}

and then

$ curl localhost:7379/PUBLISH/testing/hello
{"PUBLISH":1}

and subscriber will look like this:

$ curl -N localhost:7379/SUBSCRIBE/testing
{"SUBSCRIBE":["subscribe","testing",1]}{"SUBSCRIBE":["message","testing","hello"]}

matti avatar Oct 14 '22 15:10 matti

Ah, neat. :)

lamby avatar Oct 14 '22 15:10 lamby

6 years later :D

matti avatar Oct 14 '22 15:10 matti

I literally can't remember trying out webdis. :laughing:

lamby avatar Oct 14 '22 15:10 lamby

@lamby I know the feeling.

matti avatar Oct 14 '22 16:10 matti

Thanks for the curl tip @matti, I'll add this to the docs.

nicolasff avatar Oct 15 '22 14:10 nicolasff