Help us shape the future of Go! Take the 2026 Go Developer Survey

socket

package
v0.10.2 Latest Latest
Warning

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

Go to latest
Published: Jan 22, 2023 License: Apache-2.0 Imports: 8 Imported by: 1

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

This section is empty.

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 Handlers

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

Handlers the socket hanlders

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

Jump to

Keyboard shortcuts

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