```
2025-04-24T06:59:56Z |INFO| New session: 81ee1ed4d12c3048620fbb2168c08257
2025-04-24T07:00:10Z |INFO| Delete session: 81ee1ed4d12c3048620fbb2168c08257
2025-04-24T07:00:17Z |INFO| New session: 427ce01b7f47a7ee8192cefdfa291c8f
2025-04-24T07:00:57Z |INFO| Delete session: 427ce01b7f47a7ee8192cefdfa291c8f
2025-04-24T07:01:55Z |INFO| New session: ffbfd5c596195c2bd43b8c0b6dc3d135
2025-04-24T07:01:57Z |ERRO| websocket: close sent
panic: send on closed channel
goroutine 33 [running]:
main.(*user).WriteMsg(0xc00037e680, 0x2, {0xc000188d10, 0xc, 0xc})
/home/runner/work/rttys/rttys/user.go:52 +0x8b
main.(*broker).run(0xc00035a000)
/home/runner/work/rttys/rttys/broker.go:227 +0xf34
created by main.runRttys in goroutine 1
/home/runner/work/rttys/rttys/main.go:86 +0x595
```
Signed-off-by: Jianhui Zhao <zhaojh329@gmail.com>
rttys(中文)
This is the server program of rtty
Build from source
golang and node 20+ is required
cd ui
npm install
npm run build
cd ..
go build
Authorization(optional)
Token
Generate a token
$ rttys token
Please set a password:******
Your token is: 34762d07637276694b938d23f10d7164
Use token
$ rttys run -t 34762d07637276694b938d23f10d7164
Use your own authentication server
If the device authentication URL is configured, when the device connecting, rttys will initiate an authentication request to this URL, and the authentication server will return whether the authentication has been passed.
Request data format:
{"devid":"test", "token":"34762d07637276694b938d23f10d7164"}
Authentication Server Response Format:
{"auth": true}
mTLS
You can enable mTLS by specifying device CA storage (valid file) in config file or from CLI (variable ssl-cacert). Device(s) without valid CA in storage will be disconnected in TLS handshake.
Database Preparation
Sqlite
s#qlite://rttys.db
MySql or Mariadb
mysql://rttys:rttys@tcp(localhost)/rttys
On database instance, login to database console as root:
mysql -u root -p
Create database user which will be used by Rttys, authenticated by password. This example uses 'rttys' as password. Please use a secure password for your instance.
CREATE USER 'rttys' IDENTIFIED BY 'rttys';
Create database with UTF-8 charset and collation. Make sure to use utf8mb4 charset instead of utf8 as the former supports all Unicode characters (including emojis) beyond Basic Multilingual Plane. Also, collation chosen depending on your expected content. When in doubt, use either unicode_ci or general_ci.
CREATE DATABASE rttys CHARACTER SET 'utf8mb4' COLLATE 'utf8mb4_unicode_ci';
Grant all privileges on the database to database user created above.
GRANT ALL PRIVILEGES ON rttys.* TO 'rttys';
FLUSH PRIVILEGES;
Quit from database console by exit.
nginx proxy
# rttys.conf
addr-user: 127.0.0.1:5913
addr-http-proxy: 127.0.0.1:5914
http-proxy-redir-url: http://web.your-server.com
http-proxy-redir-domain: .your-server.com
# nginx.conf
server {
listen 80;
server_name rtty.your-server.com;
location /connect/ {
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "Upgrade";
proxy_pass http://127.0.0.1:5913;
}
location / {
proxy_pass http://127.0.0.1:5913;
}
}
server {
listen 80;
server_name web.your-server.com;
location / {
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "Upgrade";
proxy_pass http://127.0.0.1:5914;
}
}
The parameter 'http-proxy-redir-url' and 'http-proxy-redir-domain' in rttys.conf can also be configured by setting new HTTP headers in nginx.
server {
listen 80;
server_name rtty.your-server.com;
location /connect/ {
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "Upgrade";
proxy_pass http://127.0.0.1:5913;
}
location /web/ {
proxy_set_header HttpProxyRedir http://web.your-server.com;
proxy_set_header HttpProxyRedirDomain .your-server.com
proxy_pass http://127.0.0.1:5913;
}
location / {
proxy_pass http://127.0.0.1:5913;
}
}
server {
listen 80;
server_name web.your-server.com;
location / {
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "Upgrade";
proxy_pass http://127.0.0.1:5914;
}
}
Docker
Simple run
sudo docker run -it -p 5912:5912 -p 5913:5913 -p 5914:5914 zhaojh329/rttys:latest \
run --addr-http-proxy :5914
Using config file
sudo mkdir -p /opt/rttys
sudo sh -c 'echo "addr-http-proxy: :5914" > /opt/rttys/rttys.conf'
sudo docker run -it -p 5912:5912 -p 5913:5913 -p 5914:5914 -v /opt/rttys:/etc/rttys \
zhaojh329/rttys:latest run -conf /etc/rttys/rttys.conf
Contributing
If you would like to help making rttys better, see the CONTRIBUTING.md file.