Code Monkey home page Code Monkey logo

Comments (9)

jkarneges avatar jkarneges commented on May 20, 2024

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.

from pushpin.

deviantmk avatar deviantmk commented on May 20, 2024

wow thats great
i had no idea about this
thanks

from pushpin.

deviantmk avatar deviantmk commented on May 20, 2024

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

from pushpin.

jkarneges avatar jkarneges commented on May 20, 2024

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).

from pushpin.

deviantmk avatar deviantmk commented on May 20, 2024

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

from pushpin.

deviantmk avatar deviantmk commented on May 20, 2024

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

from pushpin.

deviantmk avatar deviantmk commented on May 20, 2024

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

from pushpin.

jkarneges avatar jkarneges commented on May 20, 2024

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.

from pushpin.

deviantmk avatar deviantmk commented on May 20, 2024

that makes sense
thanks a bunch

from pushpin.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.