Popularity
1.0
Stable
Activity
5.1
Stable
5
2
0

Programming language: Go
Tags: Networking    

gosocsvr alternatives and similar packages

Based on the "Networking" category.
Alternatively, view gosocsvr alternatives based on common mentions on social networks and blogs.

Do you think we are missing an alternative of gosocsvr or a related project?

Add another 'Networking' Package

README

gosocsvr

GoLang package for creating elegant socket servers.

Available Options

gosocsvr.DefaultPortRangeMin - this is the start range port

gosocsvr.DefaultPortRangeMax - this is the end range port

gosocsvr.ConfigPort - this is the port the configuration handler uses

gosocsvr.ServicePool - this is a collection of services in use

Handlers

Handlers are functions that accept an input/sender (string, string) and outputs a byte array.

Example

AuthenticationHandler

func AuthenticationHandler(input string, sender string) []byte {
    var inConv = []byte(input)
    var a AuthenticationPayload
    json.Unmarshal(inConv, &a)

    //do some authentication

    resp := AuthenticationResponse{
        SessionID: "",
        Message:   "Authentication failed",
        Code:      999,
    }
    return resp.ToJSON()
}

MessageHandler

func MessageHandler(input string, sender string) []byte {
    var inConv = []byte(input)
    var m MessagePayload
    json.Unmarshal(inConv, &m)

    //do some message handling

    resp := MessageResponse{Code: 99}
return resp.ToJSON()
}

Implementation

The only public function of the gosocsvr is the Instatiate function.

func InstantiateServerPool(handlerFunctions []func(string, string) []byte)

Parameters

handlerFunctions []func(string, string) []byte - a collection of functions

handlers are used as the server entry points allowing connection via tcp, see above examples of AuthenticationHandler or MessageHandler for an example on use.

Example

func initServerPool() {
    var serverPool = []func(string, string) []byte{
        AuthenticationHandler,
        MessageHandler,
    }
    gosocsvr.InstantiateServerPool(serverPool)
}

Working Examples

You can visit https://github.com/Rakeki/gosocsvr-example to see example code.

Configuration Server

The server will automatically listen on a specified port and output a JSON representation of the handler configuration.

[{ServiceName: "Example1", ServicePort: 2020 },{ServiceName: "Example2", ServicePort: 2022 }]