Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

client side possibility? #47634

Closed
deviantmk opened this issue Aug 6, 2016 · 9 comments
Closed

client side possibility? #47634

deviantmk opened this issue Aug 6, 2016 · 9 comments

Comments

@deviantmk
Copy link

hello

is there a library or a way to use javascript websocket to listen on a channel?
i am getting an net::ERR_EMPTY_RESPONSE

thanks

@jkarneges
Copy link
Member

jkarneges commented Aug 6, 2016

Of course. :) If you create WebSocket endpoints with Pushpin, then any WebSocket clients can connect to them, including the JavaScript WebSocket object in the browser.

Creating WebSocket endpoints requires server development though, to react to Pushpin's proxied events. Did you write any such code yet? If not, you can try Pushpin's test mode, which lets you connect and publish without having to write backend code.

First make sure your routes file is routing to the internal test service (this is the default out of the box):

* test

The test mode has a WebSocket endpoint living at /ws that automatically subscribes to a channel called test. Connect to it:

var ws = new WebSocket('ws://localhost:7999/ws');
ws.onmessage = function (message) {
  console.log(message.data);
};

Then from a terminal, you can publish using the pushpin-publish command line tool:

pushpin-publish test "hello world"

Please note that in a real application you would write backend code instead of using the test mode.

@deviantmk
Copy link
Author

wow thats great
i had no idea about this
thanks

@deviantmk
Copy link
Author

deviantmk commented Aug 7, 2016

sorry to reopen this but i am getting some errors

i botted a docker pushpin container and i created a ws server in GO server, with javascript ws i tried to connect to the go server

but the ws connection is dropped

WebSocket connection to 'ws://localhost:8080/' failed: Error during WebSocket handshake: 'Sec-WebSocket-Extensions' header value is rejected by the parser: grip; message-prefix=""

and i get this error on the server

http: panic serving [::1]:5307: Publish failed with: Post 0.0.0.0:5561/publish/: unsupported protocol scheme ""
goroutine 5 [running]:
net/http.(*conn).serve.func1(0xc08204a100)
        C:/Go/src/net/http/server.go:1389 +0xc8
panic(0x6c6f20, 0xc0820b21a0)
        C:/Go/src/runtime/panic.go:426 +0x4f7
main.GripWebSocketHandler(0x2885760, 0xc082033790, 0xc0820a61c0)
        F:/projects/go/pushpin/main.go:40 +0x87f
net/http.HandlerFunc.ServeHTTP(0x85f290, 0x2885760, 0xc082033790, 0xc0820a61c0)
        C:/Go/src/net/http/server.go:1618 +0x41
net/http.(*ServeMux).ServeHTTP(0xc082058780, 0x2885760, 0xc082033790, 0xc0820a61c0)
        C:/Go/src/net/http/server.go:1910 +0x184
net/http.serverHandler.ServeHTTP(0xc08204a080, 0x2885760, 0xc082033790, 0xc0820a61c0)
        C:/Go/src/net/http/server.go:2081 +0x1a5
net/http.(*conn).serve(0xc08204a100)
        C:/Go/src/net/http/server.go:1472 +0xf35
created by net/http.(*Server).Serve
        C:/Go/src/net/http/server.go:2137 +0x455

apparently i mixd things up, ws://localhost:7999/ was the right client port

but now i am getting

WebSocket connection to 'ws://localhost:7999/channel' failed: Error during WebSocket handshake: Unexpected response code: 502

or

Error while proxying to origin. while accessing with HTTP get request which i think shows me that its the right url/port

@deviantmk deviantmk reopened this Aug 7, 2016
@jkarneges
Copy link
Member

What does your routes file look like? Should Pushpin speak to your backend server using HTTP or WebSocket? (you mention a "ws server in GO" so I just want to be sure).

@deviantmk
Copy link
Author

hello
i have not yet touched the routes file because there were no instructions on the docker image, i am booting a linode instance and will test directly again

@deviantmk
Copy link
Author

deviantmk commented Aug 7, 2016

so what you described above with * test, should work without a server?
i am unable to get that result from the docker image

var ws = new WebSocket('ws://localhost:7999/ws');
ws.onmessage = function (message) {
  console.log(message.data);
};

WebSocket connection to 'ws://localhost:7999/ws' failed: Error during WebSocket handshake: Unexpected response code: 502

@deviantmk
Copy link
Author

deviantmk commented Aug 7, 2016

good news, directly from a linode instance works.
i am maybe doing something wrong with docker, looks like this

PORTS                                   NAMES
5560-5563/tcp, 0.0.0.0:7999->7999/tcp   pushpin

i will investigate further

@jkarneges
Copy link
Member

The docker image routes to app:8080 instead of the internal test service. See the Dockerfile. You can set the target environment variable when running the image to have it route somewhere else.

@deviantmk
Copy link
Author

that makes sense
thanks a bunch

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants