Asynchronous TCP Publishing on a Single TCP Payload

2 min read Developer Relations Team on Feb 20, 2015

PubNub-FAQs-LogoIf you’ve checked out the PubNub Developer Community before, you may have dove into the Tips, Tricks, and How-To’s section, where our developer community share tutorials, docs, and experiences developing their real-time applications using the many PubNub APIs. We love when our broad community of programming experts share their tips and tricks, and sometimes we even share a couple of our own.

In the video below, our founder and CTO Stephen Blum does just that. In this tips and tricks session, he covers three major topics:

  • Message Streaming
  • Simultaneous TCP Publishing
  • Mobile Gateways for APNs, GCM, and Windows

The video includes live coding, so open up your terminal and follow along!

Message Streaming

In this part, we show you a couple cool tricks for both message streaming and data pipelining, all in a terminal window. This enables you to publish messages asynchronously without waiting for responses or feedback from a server. These are essentially large streams of data.


connection policy here at PubNub is infinite As soon as you open a connection and send a valid payload to us, we recognize that and let you know with a response, now your socket is open forever. As long as your IP address is the same, and you don’t have any dynamic router changes in the middle, your connection remains open.

At 1:18, Stephen demonstrates this functionality and simultaneous TCP publishing. This enables you to asynchronously send multiple messages through a single TCP payload. With one MTU,  you can bundle multiple messages, chunk them together, and send one TCP package via PubNub. The code and a walkthrough for keeping a TCP socket connection open is available here, and in the video below:

You may be used to /subscribe, our standard high-availability endpoint. Streaming is a less reliable stream of data where the client itself that’s doing the subscription doesn’t have to communicate back to us. This means less log processing, but you can stream more data. (We don’t recommend this for anything outside the firewall, like mobile, but if you’re testing, it’s completely okay.

GCM, APNs, and Windows Push Notifications

Lastly, Stephen gives a brief demonstration of cross-platform push notifications, and where PubNub fits. If you need more information on mobile push notifications, we have lots of tutorials and demos listed below: