本文整理汇总了Golang中github.com/ziutek/telnet.Conn类的典型用法代码示例。如果您正苦于以下问题:Golang Conn类的具体用法?Golang Conn怎么用?Golang Conn使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Conn类的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: sendln
func sendln(t *telnet.Conn, s string) {
checkErr(t.SetWriteDeadline(time.Now().Add(timeout)))
buf := make([]byte, len(s)+1)
copy(buf, s)
buf[len(s)] = '\n'
_, err := t.Write(buf)
checkErr(err)
}
示例2: expect
func expect(t *telnet.Conn, d ...string) (err error) {
t.SetReadDeadline(time.Now().Add(timeout))
err = t.SkipUntil(d...)
if err != nil {
return err
}
return nil
}
示例3: send
func send(conn *telnet.Conn, s string, timeout time.Duration) error {
conn.SetWriteDeadline(time.Now().Add(timeout))
buf := make([]byte, len(s)+1)
copy(buf, s)
buf[len(s)] = '\n'
_, err := conn.Write(buf)
if err != nil {
return err
}
return nil
}
示例4: serveGIF
func serveGIF(conn *telnet.Conn, anim *Anim) {
writeImage(conn, anim.ImageAtTime(500))
// Close the connection when done serving
err := conn.Close()
if err != nil {
log.Print("Error closing connection:", err)
return
}
log.Print(conn.RemoteAddr(), " ] Client disconnected.")
}
示例5: writeCmd
func (t *TelnetConfig) writeCmd(tn *telnet.Conn, s string) (err error) {
buf := make([]byte, len(s)+1)
copy(buf, s)
buf[len(s)] = '\n'
_, err = tn.Write(buf)
if err != nil {
return err
}
return nil
}
示例6: readUnitl
func (t *TelnetConfig) readUnitl(tn *telnet.Conn, d ...string) (err error) {
var data []byte
data, err = tn.ReadUntil(d...)
if err != nil {
return err
}
if t.Debug {
os.Stdout.WriteString("\n")
os.Stdout.Write(data)
os.Stdout.WriteString("\n")
}
return nil
}
示例7: sendln
func sendln(t *telnet.Conn, s string) (err error) {
err = t.SetWriteDeadline(time.Now().Add(timeout))
if err != nil {
return err
}
buf := make([]byte, len(s)+1)
copy(buf, s)
buf[len(s)] = '\n'
_, err = t.Write(buf)
if err != nil {
return err
}
return nil
}
示例8: checkForMessages
func checkForMessages(t *telnet.Conn, disco *discord.Discord) (err error) {
data := []byte{}
message := ""
for {
if data, err = t.ReadUntil("\n"); err != nil {
err = fmt.Errorf("Error reading", err.Error())
return
}
message = string(data)
//log.Printf("[DEBUG OOC] %s", message)
if len(message) < 3 { //ignore small messages
continue
}
if !strings.Contains(message, "says ooc,") { //ignore non-ooc
continue
}
if strings.Index(message, ">") > 0 && strings.Index(message, ">") < strings.Index(message, " ") { //ignore prompts
message = message[strings.Index(message, ">")+1:]
}
if message[0:1] == "*" { //ignore echo backs
continue
}
sender := message[0:strings.Index(message, " says ooc,")]
message = message[strings.Index(message, "says ooc, '")+11 : len(message)-3]
sender = strings.Replace(sender, "_", " ", -1)
message = convertLinks(config.Discord.ItemUrl, message)
if _, err = disco.SendMessage(channelID, fmt.Sprintf("**%s OOC**: %s", sender, message)); err != nil {
log.Printf("[OOC] Error sending message (%s: %s) %s", sender, message, err.Error())
continue
}
log.Printf("[OOC] %s: %s\n", sender, message)
}
}
示例9: expect
func expect(t *telnet.Conn, d ...string) {
checkErr(t.SetReadDeadline(time.Now().Add(timeout)))
checkErr(t.SkipUntil(d...))
}