Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/actix/sockjs
SockJS server for rust language
https://github.com/actix/sockjs
actix rust sockjs websocket websocket-server
Last synced: about 2 months ago
JSON representation
SockJS server for rust language
- Host: GitHub
- URL: https://github.com/actix/sockjs
- Owner: actix
- License: apache-2.0
- Archived: true
- Created: 2017-10-09T17:24:01.000Z (about 7 years ago)
- Default Branch: master
- Last Pushed: 2019-11-12T21:49:42.000Z (about 5 years ago)
- Last Synced: 2024-05-27T12:07:43.131Z (7 months ago)
- Topics: actix, rust, sockjs, websocket, websocket-server
- Language: Rust
- Homepage:
- Size: 723 KB
- Stars: 62
- Watchers: 6
- Forks: 23
- Open Issues: 7
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGES.md
- License: LICENSE
Awesome Lists containing this project
- awesome-rust-cn - actix/sockjs - ci.org/actix/sockjs.svg?branch=master">](https://travis-ci.org/actix/sockjs) (Libraries / Web programming)
- awesome-rust - actix/sockjs - ci.org/actix/sockjs.svg?branch=master">](https://travis-ci.org/actix/sockjs) (Libraries / Web programming)
- awesome-rust-zh - actix/sockjs - 一个[SockJS](https://github.com/sockjs)Rust 服务器[<img src="https://api.travis-ci.org/actix/sockjs.svg?branch=master">](https://travis-ci.org/actix/sockjs) (库 / 网页编程)
README
# SockJS server [![Build Status](https://travis-ci.org/actix/sockjs.svg?branch=master)](https://travis-ci.org/actix/sockjs) [![codecov](https://codecov.io/gh/actix/sockjs/branch/master/graph/badge.svg)](https://codecov.io/gh/actix/sockjs) [![crates.io](http://meritbadge.herokuapp.com/sockjs)](https://crates.io/crates/sockjs)
[SockJS](https://github.com/sockjs) server for [Actix framework](https://github.com/actix/actix).
* [API Documentation](http://actix.github.io/sockjs/sockjs/)
* Cargo package: [sockjs](https://crates.io/crates/sockjs)
* SockJS is built with [Actix web](https://github.com/actix/actix-web)
* Minimum supported Rust version: 1.21 or later---
Actix SockJS is licensed under the [Apache-2.0 license](http://opensource.org/licenses/APACHE-2.0).
## Usage
To use `sockjs`, add this to your `Cargo.toml`:
```toml
[dependencies]
sockjs = "0.2"
```## Supported transports
* [websocket](http://tools.ietf.org/html/draft-ietf-hybi-thewebsocketprotocol-10)
* [xhr-streaming](https://secure.wikimedia.org/wikipedia/en/wiki/XMLHttpRequest#Cross-domain_requests)
* [xhr-polling](https://secure.wikimedia.org/wikipedia/en/wiki/XMLHttpRequest#Cross-domain_requests)
* [iframe-xhr-polling](https://developer.mozilla.org/en/DOM/window.postMessage)
* iframe-eventsource ([EventSource](http://dev.w3.org/html5/eventsource/) used from an [iframe via
postMessage](https://developer.mozilla.org/en/DOM/window.postMessage>))
* iframe-htmlfile ([HtmlFile](http://cometdaily.com/2007/11/18/ie-activexhtmlfile-transport-part-ii/)
used from an [iframe via postMessage](https://developer.mozilla.org/en/DOM/window.postMessage>).)
* [jsonp-polling](https://secure.wikimedia.org/wikipedia/en/wiki/JSONP)## Simple chat example
```rust
extern crate actix;
extern crate actix_web;
extern crate sockjs;use actix_web::*;
use actix::prelude::*;
use sockjs::{Message, Session, CloseReason, SockJSManager, SockJSContext};struct Chat;
/// `SockJSContext` context is required for sockjs session
impl Actor for Chat {
type Context = SockJSContext;
}/// Session has to implement `Default` trait
impl Default for Chat {
fn default() -> Chat { Chat }
}/// Sockjs session trait
impl Session for Chat {
fn opened(&mut self, ctx: &mut SockJSContext) {
ctx.broadcast("Someone joined.")
}
fn closed(&mut self, ctx: &mut SockJSContext, _: CloseReason) {
ctx.broadcast("Someone left.")
}
}/// Session has to be able to handle `sockjs::Message` messages
impl Handler for Chat {
type Result = ();fn handle(&mut self, msg: Message, ctx: &mut SockJSContext)
{
// broadcast message to all sessions
ctx.broadcast(msg);
}
}fn main() {
let sys = actix::System::new("sockjs-chat");// SockJS sessions manager
let sm: Addr = SockJSManager::::start_default();HttpServer::new(move || {
let manager = sm.clone();
Application::new()
// register SockJS application
.handler(
"/sockjs/", sockjs::SockJS::new(manager.clone()))})
.bind("127.0.0.1:8080").unwrap()
.start();// let _ = sys.run();
}
```[Full chat example](https://github.com/actix/actix-sockjs/blob/master/examples/chat.rs)