Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Lightweight stream-based WebSocket implementation for Rust.

License

Apache-2.0, MIT licenses found

Licenses found

Apache-2.0
LICENSE-APACHE
MIT
LICENSE-MIT
NotificationsYou must be signed in to change notification settings

snapview/tungstenite-rs

Repository files navigation

Lightweight stream-based WebSocket implementation forRust.

use std::net::TcpListener;use std::thread::spawn;use tungstenite::accept;/// A WebSocket echo serverfnmain(){let server =TcpListener::bind("127.0.0.1:9001").unwrap();for streamin server.incoming(){spawn(move ||{letmut websocket =accept(stream.unwrap()).unwrap();loop{let msg = websocket.read().unwrap();// We do not want to send back ping/pong messages.if msg.is_binary() || msg.is_text(){                    websocket.send(msg).unwrap();}}});}}

Take a look at the examples section to see how to write a simple client/server.

NOTE:tungstenite-rs is more like a barebone to build reliable modern networking applicationsusing WebSockets. If you're looking for a modern production-ready "batteries included" WebSocketlibrary that allows you to efficiently use non-blocking sockets and do "full-duplex" communication,take a look attokio-tungstenite.

MIT licensedApache-2.0 licensedCrates.ioBuild Status

Documentation

Introduction

This library provides an implementation of WebSockets,RFC6455. It allows for both synchronous (like TcpStream)and asynchronous usage and is easy to integrate into any third-party event loops includingMIO. The API design abstracts away all the internals of theWebSocket protocol but still makes them accessible for those who wants full control over thenetwork.

Why Tungstenite?

It's formerly WS2, the 2nd implementation of WS. WS2 is the chemical formula oftungsten disulfide, the tungstenite mineral.

Features

Tungstenite provides a complete implementation of the WebSocket specification.TLS is supported on all platforms usingnative-tls orrustls. The followingfeatures are available:

  • native-tls
  • native-tls-vendored
  • rustls-tls-native-roots
  • rustls-tls-webpki-roots

Choose the one that is appropriate for your needs.

By defaultno TLS feature is activated, so make sure you use one of the TLS features,otherwise you won't be able to communicate with the TLS endpoints.

There is no support for permessage-deflate at the moment, but the PRs are welcome 😉

Testing

Tungstenite is thoroughly tested and passes theAutobahn Test Suite forWebSockets. It is also covered by internal unit tests as well as possible.

Benchmark

Benches are in./benches.

  • Run all withcargo bench --bench \* -- --quick --noplot
  • Run a particular set with, say "e2e", withcargo bench --bench e2e -- --quick --noplot

Contributing

Please report bugs and make feature requestshere.

About

Lightweight stream-based WebSocket implementation for Rust.

Topics

Resources

License

Apache-2.0, MIT licenses found

Licenses found

Apache-2.0
LICENSE-APACHE
MIT
LICENSE-MIT

Stars

Watchers

Forks

Packages

No packages published

Contributors82


[8]ページ先頭

©2009-2025 Movatter.jp