Skip to content

Connection pooling for backend server in Go using UDP and TCP

Notifications You must be signed in to change notification settings

waterloop/wpool

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 

Repository files navigation

WPool

Connection pooling for backend server in Go using UDP for broadcasting data and TCP for relaying commands from the client

Usage

type WPool

type WPool struct {
	dataAddr    string
	commandAddr string
	commandIn   chan *wjson.CommPacketJson
	dataOut     chan *wjson.CommPacketJson
	numConns    int
	connections []net.Conn
}

func CreateWPool

func CreateWPool(dataAddr string, commandAddr string) *WPool

Creates a new WPool that broadcasts and recieves commands from the specified addresses

func Serve

func (pool *WPool) Serve()

Function that starts the connection pool for TCP and UDP, calls ServeDataChannel and ServeCommandChannel

func ServeDataChannel

func (pool *WPool) ServeDataChannel()

Broadcasts data to the WPool's port using UDP via channels

func ServeCommandChannel

func (pool *WPool) ServeCommandChannel()

Recieves TCP connections for commands and adds them to the connection pool

func GetNextCommand

func (pool *WPool) GetNextCommand() *wjson.CommPacketJson 

Returns the next command in the commandIn channel as a JSON

func CommandHandler

func (pool *WPool) CommandHandler(conn net.Conn, connIndex int) 

Handles commands via TCP from the specified connection in the pool and passes them to the commandIn channel

func CloseConn

func (pool *WPool) CloseConn(conn net.Conn, index int) 

Closes the specified TCP connection in the pool at the specified index

func BroadcastPacket

func (pool *WPool) BroadcastPacket(packet *wjson.CommPacketJson)

Passes the given packet into the WPool's dataOut channel to be broadcasted

func SendPacketByteArray

func SendPacketByteArray(dataConn *net.UDPConn, data *wjson.CommPacketJson) 

Writes the next packet in the dataOut channel to the WPool's broadcast address

About

Connection pooling for backend server in Go using UDP and TCP

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages