socket

package
v0.10.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 1, 2023 License: Apache-2.0 Imports: 13 Imported by: 1

README

Deprecated

Refactor after v0.10.3 release

Documentation

Index

Constants

View Source
const (
	// WAITING waiting for connecting
	WAITING uint = iota

	// CONNECTING connecting the host
	CONNECTING

	// CONNECTED  the socket is connected
	CONNECTED

	// CLOSED the socket is closed
	CLOSED
)
View Source
const (

	// MREAD socket read error ( the local peer closed )
	MREAD uint = iota

	// MBREAK the remote peer closed
	MBREAK

	// MCLOSE user send the CLOSE signal
	MCLOSE
)

Variables

View Source
var Sockets = map[string]*Socket{}

Sockets sockets loaded (Alpha)

Functions

func Connect

func Connect(proto string, host string, port string, timeout time.Duration, bufferSize int, KeepAlive time.Duration, handler func([]byte, int, error) ([]byte, error)) error

Connect Connect socket server (alpha -> will be refactored at a beta version...)

func Start

func Start(proto string, host string, port string, bufferSize int, KeepAlive int, handler func([]byte, int, error) ([]byte, error))

Start start socket server

Types

type Client

type Client struct {
	Status       uint
	Conn         net.Conn
	Option       Option
	Handlers     Handlers
	Attempts     int
	AttemptAfter time.Duration
	AttemptTimes int
}

Client the socket client

func NewClient

func NewClient(option Option, handlers Handlers) *Client

NewClient Create a socket client

func (*Client) Open

func (client *Client) Open() error

Open Connect the socket server

type ClosedHandler

type ClosedHandler func([]byte, error) []byte

ClosedHandler Handler

type ConnectedHandler

type ConnectedHandler func(option Option) error

ConnectedHandler Handler

type DataHandler

type DataHandler func([]byte, int) ([]byte, error)

DataHandler Handler

type ErrorHandler

type ErrorHandler func(error)

ErrorHandler Handler

type Event added in v0.10.3

type Event struct {
	Data      string `json:"data,omitempty"`
	Error     string `json:"error,omitempty"`
	Closed    string `json:"closed,omitempty"`
	Connected string `json:"connected,omitempty"`
}

Event struct

type Handlers

type Handlers struct {
	Data      DataHandler
	Error     ErrorHandler
	Closed    ClosedHandler
	Connected ConnectedHandler
}

Handlers the socket handlers

type Option

type Option struct {
	Protocol     string        `json:"protocol,omitempty"` // TCP/UDP
	Host         string        `json:"host,omitempty"`
	Port         string        `json:"port,omitempty"`
	Timeout      time.Duration `json:"timeout,omitempty"`       // timeout (seconds)
	BufferSize   int           `json:"buffer,omitempty"`        // bufferSize
	KeepAlive    time.Duration `json:"keep,omitempty"`          // -1 not keep alive, 0 keep alive always, keep alive n seconds.
	AttemptAfter time.Duration `json:"attempt_after,omitempty"` // Attempt attempt_after
	Attempts     int           `json:"attempts,omitempty"`      // max times try to reconnect server when connection break (client mode only)
}

Option the socket option

type Socket added in v0.10.3

type Socket struct {
	Name         string `json:"name"`
	Version      string `json:"version"`
	Mode         string `json:"mode,omitempty"` // Server | client
	Description  string `json:"description,omitempty"`
	Protocol     string `json:"protocol,omitempty"`
	Host         string `json:"host,omitempty"`
	Port         string `json:"port,omitempty"`
	Event        Event  `json:"event,omitempty"`
	Timeout      int    `json:"timeout,omitempty"` // timeout (seconds)
	BufferSize   int    `json:"buffer,omitempty"`  // bufferSize
	KeepAlive    int    `json:"keep,omitempty"`    // -1 not keep alive, 0 keep alive always, keep alive n seconds.
	Process      string `json:"process,omitempty"`
	AttemptAfter int    `json:"attempt_after,omitempty"` // Attempt attempt_after
	Attempts     int    `json:"attempts,omitempty"`      // max times try to reconnect server when connection break (client mode only)
	// contains filtered or unexported fields
}

Socket struct

func Load added in v0.10.3

func Load(file string, name string) (*Socket, error)

Load load socket server/client

func Select added in v0.10.3

func Select(name string) *Socket

Select Get socket by name

func (Socket) Connect added in v0.10.3

func (sock Socket) Connect(args ...interface{}) error

Connect Connect to server

func (Socket) Open added in v0.10.3

func (sock Socket) Open(args ...interface{}) error

Open Connect the socket server

func (Socket) Start added in v0.10.3

func (sock Socket) Start(args ...interface{})

Start Start server

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL