Install the package with:
go get github.com/mushroomsir/socket
Import it with:
import "github.com/mushroomsir/socket"
and use socket
as the package name inside the code.
- Simple API: use it as an easy way to reuse socket(net.conn)
- Socket support Ping() func
// create a new socket pool with an initial capacity of 5 and maximum
// capacity of 30. The factory will create 5 initial connections and put it
// into the pool.
pool, err := socket.NewPool(1, 20, socket.NewFactory(address))
// now you can get a connection from the pool, if there is no connection
// available it will create a new one via the factory function.
socket, err := pool.Get()
// Ping to detect whether the socket is closed.
b, err := socket.Ping()
// close pool any time you want
pool.Close()