# README
io
如何使用
如何连接TCP
package main
import (
"github.com/injoyai/ios"
"github.com/injoyai/ios/client"
"github.com/injoyai/ios/client/dial"
"time"
)
func main() {
addr := "127.0.0.1:10086"
c := dial.Redial(dial.WithTCP(addr),
func(c *client.Client) {
c.Logger.Debug() //开启打印日志
c.Logger.WithUTF8() //打印日志编码ASCII
c.Event.OnReadFrom = ios.NewRead4KB() //设置读取方式,一次读取全部
c.Event.OnDealMessage = func(c *client.Client, msg ios.Acker) {
// todo 业务逻辑,处理读取到的数据
}
c.GoTimerWriter(time.Minute, func(w ios.MoreWriter) error {
_, err := w.WriteString("心跳") //定时发送心跳
return err
})
})
c.Run()
}
如何连接SSH
package main
import (
"bufio"
"fmt"
"github.com/injoyai/ios/client/dial"
"github.com/injoyai/ios/module/ssh"
"os"
)
func main() {
c := dial.RedialSSH(&ssh.Config{
Address: os.Args[1],
User: os.Args[2],
Password: os.Args[3],
})
c.Logger.Debug(false)
c.Event.OnDealMessage = func(c *client.Client, msg ios.Acker) {
fmt.Print(string(msg.Payload()))
}
go c.Run()
reader := bufio.NewReader(os.Stdin)
for {
select {
case <-c.Done():
return
default:
bs, _, _ := reader.ReadLine()
c.Write(append(bs, '\n'))
}
}
}
如何连接Websocket
package main
import(
"bufio"
"github.com/injoyai/ios"
"github.com/injoyai/ios/client/dial"
"os"
)
func main(){
<- dial.RedialWebsocket("http://127.0.0.1:80/ws",nil,
func(c *client.Client) {
c.Logger.Debug()
c.Logger.WithUTF8()
c.Event.OnDealMessage= func(c *client.Client, msg ios.Acker){
// todo 业务逻辑,处理读取到的数据
}
}).Done()
}
# Functions
Bridge 桥接,桥接两个ReadWriter 例如,桥接串口(客户端)和网口(tcp客户端),可以实现通过串口上网.
No description provided by the author
No description provided by the author
No description provided by the author
CopyBufferWith 复制数据,每次固定大小,并提供函数监听 如何使用接口约束 [T Reader | MReader | AReader].
No description provided by the author
MultiCloser 多个关闭合并.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
NewRead4KB 新建读取函数,按4KB读取.
NewReadFrom 读取函数.
NewReadFromWithHandler 读取函数.
NewReadKB 新建读取函数,按KB读取.
NewReadLeast 新建读取函数,至少读取设置的字节.
NewReadMost 新建读取函数,按最大字节数读取.
Pipe 一个双向通道.
No description provided by the author
ReadByte 读取一字节.
ReadPrefix 读取Reader符合的头部,返回成功(nil),或者错误.
SplitBytesByLength 按最大长度分割字节 todo 这个不应该出现在这里.
No description provided by the author
# Variables
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
# Structs
AllRead ios.Reader转io.Reader.
No description provided by the author
No description provided by the author
No description provided by the author
Split 数据分包.
No description provided by the author
No description provided by the author
No description provided by the author
# Interfaces
Acker 兼容MQ等需要确认的场景.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
# Type aliases
No description provided by the author
No description provided by the author
No description provided by the author
CloseFunc 关闭函数.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
ReadFunc 读取函数.
WriteFunc 写入函数.
No description provided by the author
No description provided by the author
No description provided by the author