Skip to content
This repository has been archived by the owner on Dec 11, 2021. It is now read-only.
/ ServerTCP Public archive

Easy to use tcp server for golang using dependency injection

License

Notifications You must be signed in to change notification settings

alepacheco/ServerTCP

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ServerTCP

Easy to use tcp server for golang using dependency injection

Sample usage

package main

import (
  "os"
  "bufio"
  "net"
  "fmt"
  "github.com/alepacheco/ServerTCP"
)

func main() {
  // Create a server instance
  server := ServerTCP.NewServer()
  
  // Start listening for new connections in port 6666 and pass a listening function
  go server.Listen(":6666", listenFunc)
  
  // Read for clients messafes and passes a read function
  go server.Read(readFun)
	
  // Broadcast a message to all clients
  server.Broadcast("Hello clients")

}

// readFun is executed when a new message is recived
func readFun(message ServerTCP.ClientMessage) {
	fmt.Println("", message.Data, "'")
  // You can reply using message.Client.Writer (*bufio.Writer)
  
}

// listenFunc will be executed when a new client is connected 
func listenFunc(conn net.Conn) {
	fmt.Println("New connection: ", conn.RemoteAddr().String())
}

About

Easy to use tcp server for golang using dependency injection

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages