Full-duplex web server compatible with goog.net.WebChannel (from closure-library) and written in Go.

Andy Hochhaus de6fc8c5ab add timer channel draining debug code 1 year ago
.gitignore f91842ed14 Add license. 7 years ago
LICENSE da4acf952f Sync with SameGoal's repo 5 years ago
Makefile da4acf952f Sync with SameGoal's repo 5 years ago
README.md da4acf952f Sync with SameGoal's repo 5 years ago
bind.go 380e839b52 reduce mutex contention 1 year ago
forward.go a69afa31dc forward: fix compile error 1 year ago
gzip.go b06bde07d9 gzip: pool writers to reduce memory allocations 1 year ago
padder.go da4acf952f Sync with SameGoal's repo 5 years ago
padder_test.go da4acf952f Sync with SameGoal's repo 5 years ago
session.go de6fc8c5ab add timer channel draining debug code 1 year ago
sessionmanager.go 380e839b52 reduce mutex contention 1 year ago
sessionwrapper.go de6fc8c5ab add timer channel draining debug code 1 year ago
test.go eef1684a1b Add support for multiple SessionManagers 4 years ago
wc.go 80098a50f3 session: warn log slow backchannel writes 1 year ago



This library was used to build dropinchat.com for YC Hacks.

A Go web server compatible with closure-library's goog.net.WebChannel. A WebChannel represents a logical bi-directional communication channel between client and server. By exposing a generic communication interface which can be implemented over a variety of transports (eg: BrowserChannel, WebSockets, WebRTC, etc) WebChannel provides additional flexibility over programming directly on top of WebSockets.

The client-side portion of WebChannel is open sourced (APLv2) as part of closure-library. Unfortunately, Google has not released the server-side portion of the code required to use WebChannel meaningfully. The wc package provides an open source (BSD) licensed golang server-side library to fill this missing gap.

See the wcchat package for an example application.


From goog.net.WebChannel:

Similar to HTML5 WebSocket and Closure BrowserChannel, WebChannel offers an abstraction for point-to-point socket-like communication between a browser client and a remote origin.

WebChannels are created via WebChannel. Multiple WebChannels may be multiplexed over the same WebChannelTransport, which represents the underlying physical connectivity over standard wire protocols such as HTTP and SPDY.

A WebChannels in turn represents a logical communication channel between the client and server end point. A WebChannel remains open for as long as the client or server end-point allows.

Messages may be delivered in-order or out-of-order, reliably or unreliably over the same WebChannel. Message delivery guarantees of a WebChannel is to be specified by the application code; and the choice of the underlying wire protocols is completely transparent to the API users.

Client-to-client messaging via WebRTC based transport may also be support via the same WebChannel API in future.

At the time of this writing (5/2014) the only WebChannel transport included in closure-library is BrowserChannel. As additional transports are added wc intends to add support for them as well.


From goog.net.BrowserChannel:

A BrowserChannel simulates a bidirectional socket over HTTP. It is the basis of the Gmail Chat IM connections to the server.

BrowserChannel works on all major browsers (including IE5.5+) using a variety of technologies including forever iframes (IE < 10) and XHR Streaming (IE10+ and non-IE).

Client Usage (JavaScript)

To connect from the client:

  • goog.net.WebChannel.Options
  • Implement a BrowserChannel.Handler subclass
  • Instantiate a BrowserChannel and connect()
  • call channel.sendMap() to send data

 * @type {!goog.net.WebChannelTransport}
var channelTransport = goog.net.createWebChannelTransport();

 * @type {!goog.net.WebChannel.Options}
var options = { supportsCrossDomainXhr: true };

 * @type {!goog.net.WebChannel}
var channel = channelTransport.createWebChannel('/channel', options);

 * Browser channel handler.
 * @constructor
 * @extends {goog.net.BrowserChannel.Handler}
demo.ChannelHandler = function() {};
goog.inherits(demo.ChannelHandler, goog.net.BrowserChannel.Handler);

/** @inheritDoc */
demo.ChannelHandler.prototype.channelHandleArray = function(browserChannel, array) {

var handler = new demo.ChannelHandler();
var channelDebug = new goog.net.ChannelDebug();
var channel = new goog.net.BrowserChannel('8', ['<host prefix>', '<blocked prefix>']);
channel.connect('channel/test', 'channel/bind', {});



Server Usage (Go)

TODO(ahochhaus): Document

go get github.com/samegoal/wc


Demo Chat Application

Alternate Implementations


  • mdavids, upstream author of BrowserChannel, for all of the help he provided.