Git Product home page Git Product logo

webssh-demo's Introduction

服务器端文档

快速开始

使用相同 ID,分别添加 net.conn,websocket.conn

webssh := NewWebSSH()
...
conn, _ := net.Dial("tcp", "127.0.0.1:22")
wssh.AddSSHConn("$uuid", conn)
...
ws, _ := websocket.Upgrade(w, r, nil, 512, 512)
wssh.AddWebsocket("$uuid", ws)

客户端文档

消息类型

type messageType string
const (
	messageTypeStdin     = "stdin"
	messageTypeStdout    = "stdout"
	messageTypeStderr    = "stderr"
	messageTypeResize    = "resize"
	messageTypeLogin     = "login"
	messageTypePassword  = "password"
	messageTypePublickey = "publickey"
)
type message struct {
	Type messageType `json:"type"`
	Data []byte      `json:"data"`
	Cols int         `json:"cols"`
	Rows int         `json:"rows"`
}

消息协议

  1. 登录 {type:"login",data:"$username"}
  2. 验证 {type:"password",data:"$password"}
  3. 窗口大小调整 {type:"resize",cols:40,rows:80}
  4. 标准流数据
    {type:"stdin",data:"$data"} {type:"stdout",data:"$data"} {type:"stderr",data:"$data"}
    客户端发送 stdin,接收 stdout,stderr

Data 数据

消息的 data 数据使用 base64 编码传输,JavaScript 的atob & btoa可用于 base64 编码,但对 utf8 有兼容性问题,要使用decodeURIComponent & encodeURIComponent做包裹,以下是实现

function atou(encodeString) {
  return decodeURIComponent(escape(atob(encodeString)));
}
function utoa(rawString) {
  return btoa(encodeURIComponent(rawString));
}

webssh-demo's People

Contributors

myml avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.