Skip to content

Latest commit

 

History

History
59 lines (44 loc) · 918 Bytes

README.md

File metadata and controls

59 lines (44 loc) · 918 Bytes

goaio

AIO library for golang

Quick Example

  • server
import (
  "net"
  "fmt"
  "github.com/lock-free/goaio"
)

tcpServer, err := goaio.GetTcpServer(8081, func(conn net.Conn) goaio.ConnectionHandler {
  // a new connection
  connHandler := ConnectionHandler{conn, func(data []byte) {
    // handle received data
    fmt.Printf(string(data))
  }, func(err error) {}}

  // send message
  connHandler.sendBytes([]byte("hello world!"))

  return connHandler
})

if err != nil {
  panic(err)
}

go tcpServer.Accepts() // start to accept connections
  • client
import (
  "net"
  "fmt"
  "github.com/lock-free/goaio"
)

tcpClient, err := goaio.GetTcpClient("127.0.0.1", 8081, func(data []byte) {
  // get message from server
  fmt.Printf(string(data))
}, func(err error) {
  // on closed
})

if err != nil {
  panic(err)
}

// send message to server
tcpClient.sendBytes([]byte("hello world!"))