PieSocket Channels – How To Use And Best Practices

How to use them PieSocket managed WebSocket Channels to enable real-time peer-peer communications.

Let’s talk about PieSocket Channels. You can learn the basics about PieSocket PubSub channels (or channel ID) from the documentation. In this post, we will talk about some of the best practices and examples of use.

PieSocket channels are a medium for clients and a server to communicate in real-time. Unlike, other platforms such as Pusher, we also provide the client-to-client communication ability with Channels.


PieSocket Channel is a WebSocket communication channel used to enable real-time communication between clients and servers. You need to generate an API key to start using Channels, we allow 100 concurrent connections and 500k messages/day (highest to any of our competitors) with our Free plan.

PieSocket paid plans provide more than twice the number of concurrent connections and daily messages compared to Pusher and other competitors.


If you are using our WebSocket Endpoint, you will subscribe to a Channel using the following URL.

And while using the PieSocketJS library, you can subscribe to a Channel as shown below.

You can think of Channels as if it is a group of connected peers for many-to-many communication. However, one-to-one, many-to-one, and one-to-many implementations are all possible.

If you would like to create a one-to-one chatroom, simply connect both the peers to the same channel and allow no one else to join it. The logic for this can be easily written in your application in JavaScript or whichever programming language you are using.


PieSocket Channels allow you to broadcast text and JSON data. You can use JSON objects to construct custom events for your application as needed.

If you are using a third-party WebSocket client to connect to a PieSocket Channel, you can use your WebSocket Client‘s onmessage event to fetch messages/custom events.

With the PieSocketJS library you can listen to your custom events like this:

Other events available on the channel object are as follows at the time of writing this post, refer to the PieSocketJS Github repository to check for updates:

  • open
  • message
  • error
  • close


There are two possible ways to publish messages to a PieSocket Channel.

  1. REST API ( No library dependecy)
  2. WebSocket Client

Publish with REST API

We provide the following REST API to publish text or JSON data on a PieSocket Channel.

We have code examples available in PHP, NodeJS, Ruby, Python, Java, and Go on the documentation (link in the navigation menu).

Publish from WebSocket Client

This is a unique feature available to PieSocket Channels, you can enable “C2C” (client to client) communication for your API keys from the PieSocket dashboard.

Please note that enabling C2C removes the need for API Secret to publish messages and hence this should be used with security concerns in mind.

Feel free to leave a comment below or contact support for more information on PieSocket Channels.