Files
selfcare/proxy_go/public/go-telnet@v0.0.0-20180421082511-9ff0b2ab096e/echo_handler.go
2025-03-03 11:40:37 +08:00

34 lines
645 B
Go

package telnet
import (
"github.com/reiver/go-oi"
)
// EchoHandler is a simple TELNET server which "echos" back to the client any (non-command)
// data back to the TELNET client, it received from the TELNET client.
var EchoHandler Handler = internalEchoHandler{}
type internalEchoHandler struct{}
func (handler internalEchoHandler) ServeTELNET(ctx Context, w Writer, r Reader) {
var buffer [1]byte // Seems like the length of the buffer needs to be small, otherwise will have to wait for buffer to fill up.
p := buffer[:]
for {
n, err := r.Read(p)
if n > 0 {
oi.LongWrite(w, p[:n])
}
if nil != err {
break
}
}
}