Skip to content

Commit

Permalink
Update docs
Browse files Browse the repository at this point in the history
  • Loading branch information
madari committed Feb 12, 2011
1 parent 64ebbbf commit f3e0315
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 42 deletions.
35 changes: 17 additions & 18 deletions README.md
Expand Up @@ -2,28 +2,25 @@ go-socket.io
============

The `socketio` package is a simple abstraction layer for different web browser-
supported transport mechanisms. It is _meant_ to be fully compatible with the
supported transport mechanisms. It is fully compatible with the
[Socket.IO client](http://github.com/LearnBoost/Socket.IO) JavaScript-library by
[LearnBoost Labs](http://socket.io/). A couple of patches to the client library are
required due to the nature of canonicalization happening
deep within the standard `http`-package. These patches will hopefully get merged
into the official repository at some point. Meanwhile,
[use this fork of the client](http://github.com/madari/Socket.IO). Using custom codecs
the `socketio` could be perhaps used with other clients, too.
[LearnBoost Labs](http://socket.io/). By writing custom codecs the `socketio`
could be perhaps used with other clients, too.

It provides an easy way for developers to rapidly prototype with the most
popular browser transport mechanism today:

- [HTML5 WebSockets](http://dev.w3.org/html5/websockets/)
- [HTML5 WebSockets through Adobe® Flash® Sockets](https://github.com/gimite/web-socket-js)
- [Adobe® Flash® Sockets](https://github.com/gimite/web-socket-js)
- [JSONP Long Polling](http://en.wikipedia.org/wiki/JSONP#JSONP)
- [XHR Long Polling](http://en.wikipedia.org/wiki/Comet_%28programming%29#XMLHttpRequest_long_polling)
- [XHR Multipart Streaming](http://en.wikipedia.org/wiki/Comet_%28programming%29#XMLHttpRequest)
- [ActiveX HTMLFile](http://cometdaily.com/2007/10/25/http-streaming-and-internet-explorer/)

## Crash course

The `socketio` package works hand-in-hand with the standard `http` package (by
plugging itself into a configurable `http.ServeMux`) and hence it doesn't need a
plugging itself into `http.ServeMux`) and hence it doesn't need a
full network port for itself. It has an callback-style event handling API. The
callbacks are:

Expand All @@ -33,7 +30,7 @@ callbacks are:

Other utility-methods include:

- *SocketIO.Mux*
- *SocketIO.ServeMux*
- *SocketIO.Broadcast*
- *SocketIO.BroadcastExcept*
- *SocketIO.GetConn*
Expand All @@ -44,9 +41,10 @@ persists clients' pending messages (until some configurable point) if they can't
be immediately delivered. All writes are by design asynchronous and can be made
through `Conn.Send`. The server also abstracts handshaking and various keep-alive mechanisms.

Finally, the actual format on the wire is described by a separate `Codec`.
The default bundled codec, `SIOCodec`, is fully compatible with the LearnBoost's
[Socket.IO client](http://github.com/LearnBoost/Socket.IO).
Finally, the actual format on the wire is described by a separate `Codec`. The
default bundled codecs, `SIOCodec` and `SIOStreamingCodec` are fully compatible
with the LearnBoost's [Socket.IO client](http://github.com/LearnBoost/Socket.IO)
(master and development branches).

## Example: A simple chat server

Expand Down Expand Up @@ -75,11 +73,11 @@ The default bundled codec, `SIOCodec`, is fully compatible with the LearnBoost's
struct{ message []string }{[]string{c.String(), msg.Data()}})
})

sio.Mux("/socket.io/", nil)
http.Handle("/", http.FileServer("www/", "/"))
mux := sio.ServeMux()
mux.Handle("/", http.FileServer("www/", "/"))

if err := http.ListenAndServe(":8080", nil); err != nil {
log.Exit("ListenAndServe:", err)
if err := http.ListenAndServe(":8080", mux); err != nil {
log.Fatal("ListenAndServe:", err)
}
}

Expand All @@ -90,6 +88,7 @@ You can get the code and run the bundled example by following these steps:
$ git clone git://github.com/madari/go-socket.io.git
$ cd go-socket.io
$ git submodule update --init --recursive
$ make install
$ cd example
$ make
$ ./example
Expand All @@ -98,7 +97,7 @@ You can get the code and run the bundled example by following these steps:

(The MIT License)

Copyright (c) 2010 Jukka-Pekka Kekkonen <karatepekka@gmail.com>
Copyright (c) 2011 Jukka-Pekka Kekkonen <karatepekka@gmail.com>

Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
Expand Down
50 changes: 26 additions & 24 deletions doc.go
@@ -1,36 +1,37 @@
/*
The socketio package is a simple abstraction layer for different web browser-
supported transport mechanisms. It is meant to be fully compatible with the
supported transport mechanisms. It is fully compatible with the
Socket.IO client side JavaScript socket API library by LearnBoost Labs
(http://socket.io/), but through custom formatters it might fit other client
(http://socket.io/), but through custom codecs it might fit other client
implementations too.
It (together with the LearnBoost's client-side libraries) provides an easy way for
developers to access the most popular browser transport mechanism today:
multipart- and long-polling XMLHttpRequests, HTML5 WebSockets and
forever-frames [TODO]. The socketio package works hand-in-hand with the standard
forever-frames. The socketio package works hand-in-hand with the standard
http package by plugging itself into a configurable ServeMux. It has an callback-style
API for handling connection events. The callbacks are:
- SocketIO.OnConnect
- SocketIO.OnDisconnect
- SocketIO.OnMessage
- SocketIO.OnConnect
- SocketIO.OnDisconnect
- SocketIO.OnMessage
Other utility-methods include:
- SocketIO.Mux
- SocketIO.Broadcast
- SocketIO.BroadcastExcept
- SocketIO.GetConn
- Conn.Send
- SocketIO.ServeMux
- SocketIO.Broadcast
- SocketIO.BroadcastExcept
- SocketIO.GetConn
- Conn.Send
Each new connection will be automatically assigned an unique session id and
using those the clients can reconnect without losing messages: the server
persists clients' pending messages (until some configurable point) if they can't
be immediately delivered. All writes through `Conn.Send` by design asynchronous.
be immediately delivered. All writes through Conn.Send by design asynchronous.
Finally, the actual format on the wire is described by a separate `Codec`.
The default codec is compatible with the LearnBoost's Socket.IO client.
Finally, the actual format on the wire is described by a separate Codec.
The default codecs (SIOCodec and SIOStreamingCodec) are compatible with the
LearnBoost's Socket.IO client.
For example, here is a simple chat server:
Expand All @@ -43,28 +44,29 @@
)
func main() {
sio := socketio.NewSocketIO(nil, nil)
sio.Mux("/socket.io/", nil)
http.Handle("/", http.FileServer("www/", "/"))
sio := socketio.NewSocketIO(nil)
sio.OnConnect(func(c *socketio.Conn) {
sio.Broadcast(struct{ announcement string }{"connected: " + c.String()})
})
sio.OnDisconnect(func(c *socketio.Conn) {
sio.BroadcastExcept(c, struct{ announcement string }{"disconnected: " + c.String()})
sio.BroadcastExcept(c,
struct{ announcement string }{"disconnected: " + c.String()})
})
sio.OnMessage(func(c *socketio.Conn, msg string) {
sio.OnMessage(func(c *socketio.Conn, msg socketio.Message) {
sio.BroadcastExcept(c,
struct{ message []string }{[]string{c.String(), msg}})
struct{ message []string }{[]string{c.String(), msg.Data()}})
})
log.Println("Server started.")
if err := http.ListenAndServe(":8080", nil); err != nil {
log.Exitln("ListenAndServer:", err)
mux := sio.ServeMux()
mux.Handle("/", http.FileServer("www/", "/"))
if err := http.ListenAndServe(":8080", mux); err != nil {
log.Fatal("ListenAndServe:", err)
}
}
*/
package socketio

0 comments on commit f3e0315

Please sign in to comment.