Skip to content
/ io Public

万物皆IO,老和io包引入冲突,核心功能准备迁移至ios

Notifications You must be signed in to change notification settings

injoyai/io

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

io

如何使用

如何连接TCP

    import (
        "github.com/injoyai/io"
        "github.com/injoyai/io/dial"
    )

    func main() {
        addr := "127.0.0.1:10086"
        c:=io.Redial(dial.TCPFunc(addr),
            func(c *io.Client) {
                c.Debug()             //开启打印日志
                c.SetPrintWithASCII() //打印日志编码ASCII
                c.SetReadWithAll()    //设置读取方式,一次读取全部
                c.SetDealFunc(func(c *io.Client, msg io.Message) {
                    // todo 业务逻辑,处理读取到的数据
                })
                c.GoTimerWriter(time.Minute, func(c *io.IWriter) (int, error) {
                    return c.WriteString("心跳") //定时发送心跳
                })
            })
        <-c.DoneAll()
    }
		

如何连接SSH

import (
    "github.com/injoyai/io"
    "github.com/injoyai/io/dial"
)


func main () {
	c, err := dial.RedialSSH(&SSHConfig{
		Addr:     os.Args[1],
		User:     os.Args[2],
		Password: os.Args[3],
	})
	if err != nil {
		logs.Err(err)
		return
	}
	c.Debug(false)
	c.SetDealFunc(func(c *io.Client, msg io.Message) {
		fmt.Print(msg.String())
	})
	go c.Run()
	reader := bufio.NewReader(os.Stdin)
	for {
		select {
		case <-c.DoneAll():
			return
		default:
			bs, _, _ := reader.ReadLine()
			c.Write(bs)
		}
	}
}

About

万物皆IO,老和io包引入冲突,核心功能准备迁移至ios

Topics

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages