PUBLISH/SUBSCRIBE doesn't appear to work
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?
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);
}
};
but jquery seems not support it!
That would appear to be an entirely separate issue.
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"]}
Ah, neat. :)
6 years later :D
I literally can't remember trying out webdis. :laughing:
@lamby I know the feeling.
Thanks for the curl tip @matti, I'll add this to the docs.