github.com/insionng/yougam@v0.0.0-20170714101924-2bc18d833463/libraries/igm/sockjs-go.v2/README.md (about) 1 本版本经过我修改以支持session.Request(),请勿使用官方版本替换本库! 2 By Insion 3 2016.4.28.PM 4 === 5 [](https://travis-ci.org/igm/sockjs-go) [](http://godoc.org/gopkg.in/igm/sockjs-go.v2/sockjs) [](https://coveralls.io/r/igm/sockjs-go?branch=v2) 6 7 What is SockJS? 8 = 9 10 SockJS is a JavaScript library (for browsers) that provides a WebSocket-like 11 object. SockJS gives you a coherent, cross-browser, Javascript API 12 which creates a low latency, full duplex, cross-domain communication 13 channel between the browser and the web server, with WebSockets or without. 14 This necessitates the use of a server, which this is one version of, for GO. 15 16 17 SockJS-Go server library 18 = 19 20 SockJS-Go is a [SockJS](https://github.com/sockjs/sockjs-client) server library written in Go. 21 22 To use current stable version **v2** 23 24 go get gopkg.in/igm/sockjs-go.v2/sockjs 25 26 To use previous version **v1** (DEPRECATED) 27 28 go get gopkg.in/igm/sockjs-go.v1/sockjs 29 30 To install **development** version of `sockjs-go` run: 31 32 go get github.com/igm/sockjs-go/sockjs 33 34 35 Versioning 36 - 37 38 SockJS-Go project adopted [gopkg.in](http://gopkg.in) approach for versioning. SockJS-Go library details can be found [here](https://gopkg.in/igm/sockjs-go.v2/sockjs) 39 40 41 Example 42 - 43 44 A simple echo sockjs server: 45 46 47 ```go 48 package main 49 50 import ( 51 "log" 52 "net/http" 53 54 "gopkg.in/igm/sockjs-go.v2/sockjs" 55 ) 56 57 func main() { 58 handler := sockjs.NewHandler("/echo", sockjs.DefaultOptions, echoHandler) 59 log.Fatal(http.ListenAndServe(":8081", handler)) 60 } 61 62 func echoHandler(session sockjs.Session) { 63 for { 64 if msg, err := session.Recv(); err == nil { 65 session.Send(msg) 66 continue 67 } 68 break 69 } 70 } 71 ``` 72 73 74 SockJS Protocol Tests Status 75 - 76 SockJS defines a set of [protocol tests](https://github.com/sockjs/sockjs-protocol) to quarantee a server compatibility with sockjs client library and various browsers. SockJS-Go server library aims to provide full compatibility, however there are couple of tests that don't and probably will never pass due to reasons explained in table below: 77 78 79 | Failing Test | Explanation | 80 | -------------| ------------| 81 | **XhrPolling.test_transport** | does not pass due to a feature in net/http that does not send content-type header in case of StatusNoContent response code (even if explicitly set in the code), [details](https://code.google.com/p/go/source/detail?r=902dc062bff8) | 82 | **WebSocket.** | Sockjs Go version supports RFC 6455, draft protocols hixie-76, hybi-10 are not supported | 83 | **JSONEncoding** | As menioned in [browser quirks](https://github.com/sockjs/sockjs-client#browser-quirks) section: "it's advisable to use only valid characters. Using invalid characters is a bit slower, and may not work with SockJS servers that have a proper Unicode support." Go lang has a proper Unicode support | 84 | **RawWebsocket.** | The sockjs protocol tests use old WebSocket client library (hybi-10) that does not support RFC 6455 properly | 85 86 WebSocket 87 - 88 As mentioned above sockjs-go library is compatible with RFC 6455. That means the browsers not supporting RFC 6455 are not supported properly. There are no plans to support draft versions of WebSocket protocol. The WebSocket support is based on [Gorilla web toolkit](http://www.gorillatoolkit.org/pkg/websocket) implementation of WebSocket. 89 90 For detailed information about browser versions supporting RFC 6455 see this [wiki page](http://en.wikipedia.org/wiki/WebSocket#Browser_support).