# SockJS-client
[![npm version](https://img.shields.io/npm/v/sockjs-client.svg?style=flat-square)](https://www.npmjs.com/package/sockjs-client)[![Build Status](https://img.shields.io/travis/sockjs/sockjs-client/master.svg?style=flat-square)](https://travis-ci.org/sockjs/sockjs-client)[![Dependencies](https://img.shields.io/david/sockjs/sockjs-client.svg?style=flat-square)](https://david-dm.org/sockjs/sockjs-client)[![Chat](https://img.shields.io/badge/Chat-gitter.im-blue.svg?style=flat-square)](https://gitter.im/sockjs/sockjs-client)
[![Sauce Test Status](https://saucelabs.com/buildstatus/brycekahle)](https://saucelabs.com/u/brycekahle)
SockJS is a browser JavaScript library that provides a WebSocket-like
object. SockJS gives you a coherent, cross-browser, Javascript API
which creates a low latency, full duplex, cross-domain communication
channel between the browser and the web server.
Under the hood SockJS tries to use native WebSockets first. If that
fails it can use a variety of browser-specific transport protocols and
presents them through WebSocket-like abstractions.
SockJS is intended to work for all modern browsers and in environments
which don't support the WebSocket protocol -- for example, behind restrictive
corporate proxies.
SockJS-client does require a server counterpart:
* [SockJS-node](https://github.com/sockjs/sockjs-node) is a SockJS
server for Node.js.
Philosophy:
* The API should follow
[HTML5 Websockets API](http://dev.w3.org/html5/websockets/) as
closely as possible.
* All the transports must support cross domain connections out of the
box. It's possible and recommended to host a SockJS server on a
different server than your main web site.
* There is support for at least one streaming protocol for every
major browser.
* Streaming transports should work cross-domain and
should support cookies (for cookie-based sticky sessions).
* Polling transports are used as a fallback for old browsers and
hosts behind restrictive proxies.
* Connection establishment should be fast and lightweight.
* No Flash inside (no need to open port 843 - which doesn't work
through proxies, no need to host 'crossdomain.xml', no need
[to wait for 3 seconds](https://github.com/gimite/web-socket-js/issues/49)
in order to detect problems)
Subscribe to
[SockJS mailing list](https://groups.google.com/forum/#!forum/sockjs) for
discussions and support.
SockJS family:
* [SockJS-client](https://github.com/sockjs/sockjs-client) JavaScript client library
* [SockJS-node](https://github.com/sockjs/sockjs-node) Node.js server
* [SockJS-erlang](https://github.com/sockjs/sockjs-erlang) Erlang server
* [SockJS-cyclone](https://github.com/flaviogrossi/sockjs-cyclone) Python/Cyclone/Twisted server
* [SockJS-tornado](https://github.com/MrJoes/sockjs-tornado) Python/Tornado server
* [SockJS-twisted](https://github.com/DesertBus/sockjs-twisted/) Python/Twisted server
* [Spring Framework](http://projects.spring.io/spring-framework) Java [client](http://docs.spring.io/spring-framework/docs/current/spring-framework-reference/html/websocket.html#websocket-fallback-sockjs-client) & server
* [vert.x](https://github.com/vert-x/vert.x) Java/vert.x server
* [Xitrum](http://xitrum-framework.github.io/) Scala server
* [Atmosphere Framework](http://github.com/Atmosphere/atmosphere) JavaEE Server, Play Framework, Netty, Vert.x
Work in progress:
* [SockJS-ruby](https://github.com/nyarly/sockjs-ruby)
* [SockJS-netty](https://github.com/cgbystrom/sockjs-netty)
* [SockJS-gevent](https://github.com/ksava/sockjs-gevent) ([SockJS-gevent fork](https://github.com/njoyce/sockjs-gevent))
* [pyramid-SockJS](https://github.com/fafhrd91/pyramid_sockjs)
* [wildcloud-websockets](https://github.com/wildcloud/wildcloud-websockets)
* [wai-SockJS](https://github.com/Palmik/wai-sockjs)
* [SockJS-perl](https://github.com/vti/sockjs-perl)
* [SockJS-go](https://github.com/igm/sockjs-go/)
Getting Started
-------
SockJS mimics the [WebSockets API](http://dev.w3.org/html5/websockets/),
but instead of `WebSocket` there is a `SockJS` Javascript object.
First, you need to load the SockJS JavaScript library. For example, you can
put that in your HTML head:
```html
<script src="//cdn.jsdelivr.net/sockjs/1/sockjs.min.js"></script>
```
After the script is loaded you can establish a connection with the
SockJS server. Here's a simple example:
```javascript
var sock = new SockJS('http://mydomain.com/my_prefix');
sock.onopen = function() {
console.log('open');
};
sock.onmessage = function(e) {
console.log('message', e.data);
};
sock.onclose = function() {
console.log('close');
};
sock.send('test');
sock.close();
```
SockJS-client API
-----------------
### SockJS class
Similar to the 'WebSocket' API, the 'SockJS' constructor takes one, or more arguments:
```javascript
var sockjs = new SockJS(url, _reserved, options);
```
`url` may contain a query string, if one is desired.
Where `options` is a hash which can contain:
* **server (string)**
String to append to url for actual data connection. Defaults to a random 4 digit number.
* **transports (string OR array of strings)**
Sometimes it is useful to disable some fallback transports. This
option allows you to supply a list transports that may be used by
SockJS. By default all available transports will be used.
* **sessionId (number OR function)**
Both client and server use session identifiers to distinguish connections.
If you specify this option as a number, SockJS will use its random string
generator function to generate session ids that are N-character long
(where N corresponds to the number specified by **sessionId**).
When you specify this option as a function, the function must return a
randomly generated string. Every time SockJS needs to generate a session
id it will call this function and use the returned string directly.
If you don't specify this option, the default is to use the default random
string generator to generate 8-character long session ids.
Although the 'SockJS' object tries to emulate the 'WebSocket'
behaviour, it's impossible to support all of its features. An
important SockJS limitation is the fact that you're not allowed to
open more than one SockJS connection to a single domain at a time.
This limitation is caused by an in-browser limit of outgoing
connections - usually [browsers don't allow opening more than two
outgoing connections to a single domain](http://stackoverflow.com/questions/985431/max-parallel-http-connections-in-a-browser). A single SockJS session
requires those two connections - one for downloading data, the other for
sending messages. Opening a second SockJS session at the same time
would most likely block, and can result in both sessions timing out.
Opening more than one SockJS connection at a time is generally a
bad practice. If you absolutely must do it, you can use
multiple subdomains, using a different subdomain for every
SockJS connection.
Supported transports, by browser (html served from http:// or https://)
-----------------------------------------------------------------------
_Browser_ | _Websockets_ | _Streaming_ | _Polling_
----------------|------------------|-------------|-------------------
IE 6, 7 | no | no | jsonp-polling
IE 8, 9 (cookies=no) | no | xdr-streaming † | xdr-polling †
IE 8, 9 (cookies=yes)| no | iframe-htmlfile | iframe-xhr-polling
IE 10 | rfc6455 | xhr-streaming | xhr-polling
Chrome 6-13 | hixie-76 | xhr-streaming | xhr-polling
Chrome 14+ | hybi-10 / rfc6455| xhr-streaming | xhr-polling
Firefox <10 | no ‡ | xhr-streaming | xhr-polling
Firefox 10+ | hybi-10 / rfc6455| xhr-streaming | xhr-polling
Safari 5.x | hixie-76 | xhr-streaming | xhr-polling
Safari 6+ | r
没有合适的资源?快使用搜索试试~ 我知道了~
温馨提示
如果您下载了本程序,但是该程序存在问题无法运行,那么您可以选择退款或者寻求我们的帮助(如果找我们帮助的话,是需要追加额外费用的)。另外,您不会使用资源的话(这种情况不支持退款),也可以找我们帮助(需要追加额外费用) 随着移动互联网技术的发展和用户需求的变化,【小程序名称】应运而生,以其轻量化、便捷化的设计理念为用户提供了一种全新的服务模式。作为一款无需下载安装即可使用的应用,【小程序名称】依托于微信庞大的生态系统,让用户在微信内就能轻松实现各种功能操作。 【小程序名称】的核心功能主要集中在【具体服务领域】,例如在线购物、本地生活服务、教育学习或健康管理等。它简化了传统APP繁琐的注册登录流程,支持微信一键授权登录,极大地提升了用户体验。用户通过搜索或扫描二维码,瞬间即可开启使用,享受快速加载、流畅运行的服务。 该小程序界面设计简洁明了,布局合理,易于上手。同时,其特色功能如实时更新的信息推送、个性化推荐以及社交分享功能,让用户能够及时获取所需信息,并方便地将优质内容分享至朋友圈或好友,实现信息的高效传播与互动。 【小程序名称】注重数据安全与隐私保护,严格遵守国家法律法规和微信平台的规定,确保用户数据的安全无虞。此外,其背后的开发团队持续迭代更新,根据用户反馈不断优化产品性能,提升服务质量,致力于打造一个贴近用户需求、充满活力的小程序生态。 总结来说,【小程序名称】凭借其小巧便携、快捷高效的特性,不仅节省了用户的手机存储空间,更为用户提供了无缝衔接的便利服务,是现代生活中不可或缺的一部分,真正实现了“触手可及”的智能生活新体验。只需轻点屏幕,无限精彩尽在掌握之中。
资源推荐
资源详情
资源评论
收起资源包目录
基于jhipster构建的微信小程序导航 .zip (2000个子文件)
bootstrap.css 143KB
bootstrap.min.css 118KB
screen.css 48KB
screen.css 48KB
print.css 45KB
print.css 45KB
bootstrap-theme.css 26KB
bootstrap-theme.min.css 23KB
style.css 5KB
style.css 5KB
loading-bar.css 3KB
loading-bar.css 3KB
loading-bar.min.css 2KB
prettify-tomorrow.css 2KB
prettify-jsdoc.css 1KB
integration.css 1KB
reset.css 1KB
reset.css 1KB
typography.css 452B
typography.css 452B
angular-csp.css 343B
style.css 229B
messageformat.js.html 22KB
metrics.html 19KB
MessageFormat.html 18KB
Runtime.html 16KB
index.html 14KB
index.html 13KB
navbar.html 12KB
register.html 8KB
index.html 8KB
wx-apps.html 6KB
settings.html 6KB
user-management-dialog.html 5KB
wx-app-dialog.html 5KB
comments.html 5KB
reset.finish.html 5KB
user-management.html 5KB
MessageFormat.formatters.html 5KB
categories.html 4KB
error.html 4KB
tags.html 4KB
index.html 4KB
index.html 4KB
password.html 4KB
comment-dialog.html 3KB
metrics.modal.html 3KB
login.html 3KB
reset.request.html 3KB
index.html 2KB
category-dialog.html 2KB
tag-dialog.html 2KB
user-management-detail.html 2KB
audits.html 2KB
configuration.html 2KB
wx-app-detail.html 2KB
logs.html 2KB
sessions.html 2KB
health.html 1KB
health.modal.html 1KB
home.html 1KB
comment-detail.html 1KB
404.html 1KB
social-register.html 1KB
category-delete-dialog.html 1KB
comment-delete-dialog.html 1KB
wx-app-delete-dialog.html 1KB
tag-delete-dialog.html 1KB
user-management-delete-dialog.html 1KB
category-detail.html 1KB
index.html 1KB
tag-detail.html 1015B
tracker.html 929B
activationEmail.html 863B
passwordResetEmail.html 856B
creationEmail.html 842B
socialRegistrationValidationEmail.html 743B
activate.html 693B
o2c.html 449B
o2c.html 449B
error.html 427B
accessdenied.html 412B
social.html 401B
docs.html 179B
CustomSocialUsersConnectionRepositoryIntTest.java 24KB
AccountResourceIntTest.java 16KB
WxAppResourceIntTest.java 16KB
SocialServiceIntTest.java 13KB
CommentResourceIntTest.java 12KB
AccountResource.java 11KB
CategoryResourceIntTest.java 11KB
UserService.java 10KB
TagResourceIntTest.java 10KB
CustomSocialConnectionRepository.java 9KB
UserResource.java 9KB
PersistentTokenRememberMeServices.java 8KB
WxApp.java 7KB
SocialConfiguration.java 6KB
WebConfigurer.java 6KB
CategoryResource.java 6KB
共 2000 条
- 1
- 2
- 3
- 4
- 5
- 6
- 20
资源评论
JJJ69
- 粉丝: 6222
- 资源: 5780
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- 演讲稿.txt
- 基于Python的爬虫案例-软科中国大学TOP200
- 碳排放权交易明细数据(2024年5月更新).xlsx
- 特殊文件属性命令chattr和lsattr
- HTML、CSS 和 JavaScript动态、交互式的网页 .txt
- b0cd8f9b23d4e5e381b6a8fd8ee0e907.JPG
- ff45d61c5900e45634cf4cac6cff61a1.JPG
- springboot.springboot.springboot.springboot.txt
- linux-进程与服务管理
- 毕业设计基于Django+MySQL+Redis实现简单的天气预报系统python源码.zip
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功