GithubHelp home page GithubHelp logo

gopherjs-rpc's Introduction

gopherjs-rpc

Example of use of gopherjs + websocket + jsonrpc

Preparation

  • Have Go 1.4 or better (gopherjs requirement)
  • go get -u -v github.com/gopherjs/gopherjs [godoc]
  • go get -u -v github.com/gopherjs/websocket [godoc]
  • go get -u -v honnef.co/go/js/dom [godoc]

Get the code and run!

  • cd $GOROOT (or to any of the directories featured in your $GOROOT if you have more than one, like me)
  • git clone https://github.com/dustywilson/gopherjs-rpc.git
  • cd gopherjs-rpc
  • cd www to enter the www directory where the client.go file is waiting for you to build
  • gopherjs build -m -o client.js to build the client.go file into client.js
  • cd .. to return to parent
  • go run server.go to run the server-side
  • Go to http://localhost:5454/ in your browser

If you got log messages in the browser dev console, it's working. The Output line is what the JavaScript client is sending to the Go server. The Input line is what the Go server sends to the client in response. The only thing that differs in each message is the timestamp. The server spits out the same info to the console on its end as well.

Notes

Notice that both the backend and frontend share the file in the shared directory. In this case, they use that to share the ChatMessage struct. For the most part, you can share code between frontend and backend.

You CAN'T use the core websocket lib with gopherjs. If you start getting errors saying something like gopherjs doesn't support network then you've used the wrong package.

This is rpc on top of websocket. In this case, the web browser is hosting RPC for the server to call. For as long as the client is connected to the server, the server is able to call on any of its RPC functions. Totally backwards, but really cool that it's possible.

gopherjs-rpc's People

Contributors

emmaly avatar

Watchers

 avatar  avatar  avatar

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.