Skip to content

Instantly share code, notes, and snippets.

@changtimwu
Last active March 4, 2016 02:50
Show Gist options
  • Save changtimwu/c65ab550242138a2d94f to your computer and use it in GitHub Desktop.
Save changtimwu/c65ab550242138a2d94f to your computer and use it in GitHub Desktop.
go multisession CLI scratch

https://github.com/golang/crypto/tree/master/ssh/terminal looks great

please run it with

package main

import (
    "fmt"
    "golang.org/x/crypto/ssh/terminal"
    "io"
    "log"
    "net"
)

func cliSession(c io.ReadWriter) {
    tt := terminal.NewTerminal(c, "> ")
    tt.SetSize(80, 24)
    for i := 0; ; i++ {
        s, _ := tt.ReadLine()
        fmt.Println("s=", s)
    }
}

const listenAddr = "localhost:4000"

func main() {
    l, err := net.Listen("tcp", listenAddr)
    if err != nil {
        log.Fatal(err)
    }

    for {
        c, err := l.Accept()
        if err != nil {
            log.Fatal(err)
        }
        go cliSession(c)
    }
}

client

socat -,raw,echo=0 tcp:localhost:4000
@changtimwu
Copy link
Author

@changtimwu
Copy link
Author

fallback to this if the above approach doesn't work at all
https://github.com/peterh/liner

@IS-KH
Copy link

IS-KH commented Mar 4, 2016

socat -,raw,echo=0,escape=0x03 tcp:localhost:4000

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment