O'Reilly logo

Functional Web Development with Elixir, OTP, and Phoenix by Lance Halvorsen

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Establish a Client Connection

Our goal in this section is to write client code that can invoke the join/3 function we now have on the server. There are a few steps we’ll need to take to make that happen.

We’ll need to define a client socket and use it to establish a connection to the socket on the server. Then we’ll need to define a new channel object on the client, and use it to join the channel on the server.

Phoenix ships with phoenix.js, a JavaScript file that knows all about working with sockets and channels. It’s indispensable for writing JavaScript client code for channels, and our first task is to make it available in the browser’s console window.

Let’s go to player1’s JavaScript console—that’s the browser window on the left—and require ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required