Skip to content


Subversion checkout URL

You can clone with
Download ZIP
Latest commit 9badcb2 @stephenlb stephenlb Update

PubNub Websockets

New update! - SEE: Websocket Client Interface

The following code and docs below are legacy!!! Make sure to visit the link above.

WebSocket Client Interface

Optionally PubNub offers you the full RFC 6455 Support for WebSocket Client Specification. PubNub WebSockets enables any browser (modern or not) to support the HTML5 WebSocket standard APIs. Use the WebSocket Client Directly in your Browser that Now you can use new WebSocket any time!

You will need to hit the right resource URLs. Make sure to follow the examples below.

Here is a quick example providing an easy adapter:

WebSocket  =;
var socket = new WebSocket('wss://');

Alternatively you may directly access the PubNub WebSocket via:

var socket = new'wss://')

The following example opens a new WebSocket in WSS Secure Socket Mode with 2048 Bit SSL Encryption.

<!-- Import PubNub Core Lib -->
<script src=""></script>

<!-- Use WebSocket Constructor for a New Socket Connection -->
<script>(function() {

    WebSocket  =;
    var socket = new WebSocket('wss://')

    // On Message Receive
    socket.onmessage = function(evt) {
        console.log('socket receive');

    // On Socket Close
    socket.onclose = function() {
        console.log('socket closed');

    // On Error
    socket.onerror = function() {
        console.log('socket error');

    // On Connection Establish
    socket.onopen = function(evt) {
        console.log('socket open');

        // Send a Message!
        socket.send('hello world!');

    // On Send Complete
    socket.onsend = function(evt) {
        console.log('socket send');



To Disable SSL WSS Secure Sockets:

<!-- NON-SSL Import PubNub Core Lib -->
<script src=""></script>

<!-- NON-SSL Use WebSocket Constructor for a New Socket Connection -->
<script>(function() {

// Note "ws://" rather than "wss://"
WebSocket  =;
var socket = new WebSocket('ws://')

Something went wrong with that request. Please try again.