Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/injoyai/io
万物皆IO
https://github.com/injoyai/io
io proxy serial tcp udp websokcet
Last synced: 2 months ago
JSON representation
万物皆IO
- Host: GitHub
- URL: https://github.com/injoyai/io
- Owner: injoyai
- Created: 2023-01-08T09:37:15.000Z (about 2 years ago)
- Default Branch: main
- Last Pushed: 2024-06-28T02:22:11.000Z (7 months ago)
- Last Synced: 2024-06-28T04:25:48.322Z (7 months ago)
- Topics: io, proxy, serial, tcp, udp, websokcet
- Language: Go
- Homepage:
- Size: 13.2 MB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# io
### 如何使用
#### 如何连接TCP
```go
package main
import (
"github.com/injoyai/io"
"github.com/injoyai/io/dial"
"time"
)func main() {
addr := "127.0.0.1:10086"
c := io.Redial(dial.WithTCP(addr),
func(c *io.Client) {
c.Debug() //开启打印日志
c.SetPrintWithUTF8() //打印日志编码ASCII
c.SetReadWith1KB() //设置读取方式,一次读取全部
c.SetDealFunc(func(c *io.Client, msg io.Message) {
// todo 业务逻辑,处理读取到的数据
})
c.GoTimerWriter(time.Minute, func(w *io.Client) error {
_,err:= w.WriteString("心跳") //定时发送心跳
return err
})
})
<-c.DoneAll()
}```
#### 如何连接SSH
```go
package main
import (
"bufio"
"github.com/injoyai/io"
"github.com/injoyai/io/dial"
"os"
)func main() {
c := dial.RedialSSH(&dial.SSHConfig{
Addr: os.Args[1],
User: os.Args[2],
Password: os.Args[3],
})
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)
}
}
}```
#### 如何连接Websocket
```go
package mainimport(
"bufio"
"github.com/injoyai/io"
"github.com/injoyai/io/dial"
"os"
)func main(){
<- dial.RedialWebsocket("http://127.0.0.1:80/ws",nil,
func(c *io.Client) {
c.Debug()
c.SetPrintWithUTF8()
c.SetDealFunc(func(c *io.Client, msg io.Message) {
//处理数据
})
}).DoneAll()
}```