tcp

package
v0.24.3 Latest Latest
Warning

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

Go to latest
Published: Jan 21, 2024 License: GPL-3.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client manages multiple service connections. This struct is responsible for managing connections to different services identified by their addresses.

func NewClient

func NewClient() *Client

NewClient creates a new instance of Client. It initializes the client with an empty map for managing services.

Returns: - *Client: Newly created instance of Client.

func (*Client) Close added in v0.23.24

func (c *Client) Close() error

Close closes all service connections managed by the client. It iterates over all services and closes each connection.

Returns: - error: Error, if any occurred during the closure of services.

func (*Client) Connect

func (c *Client) Connect(address string, nbInstances ...int) (*Service, error)

Connect establishes a service connection for a given address. It creates an instance of Service for network interactions.

Parameters: - address: string The TCP address to connect to. - nbInstances: ...int Optional parameter to specify the number of instances to create (default is 1).

Returns: - *Service: Instance of the Service for the specified address. - error: Error, if any occurred during the connection setup.

type Connection added in v0.23.24

type Connection struct {
	// contains filtered or unexported fields
}

type Server

type Server struct {
	Address string // Address to listen on
	// contains filtered or unexported fields
}

Server represents a TCP server and contains information about the address it listens on and the underlying network listener.

func NewServer

func NewServer(address string) *Server

NewServer creates a new Server instance with the specified listening address.

func (*Server) Register

func (s *Server) Register(api router.EndPoint)

Register is a method for registering API handlers with the server.

Parameters: - api: router.EndPoint - The EndPoint to register handlers from.

func (*Server) Start

func (s *Server) Start() error

Start starts the TCP server, allowing it to accept incoming connections.

Returns: - error: An error if the server is already started or if there was an issue starting the server.

func (*Server) Stop

func (s *Server) Stop() error

Stop stops the TCP server.

Returns: - error: An error if the server is not active or if there was an issue stopping the server.

func (*Server) TCPHandler added in v0.23.24

func (s *Server) TCPHandler(b []byte)

TCPHandler handles TCP requests by unmarshalling, processing, and marshalling responses. It is responsible for converting raw byte data into a structured request, processing it using a router, and then returning the structured response as byte data. It handles errors at each step by returning an empty response in case of failure.

Parameters: - b: []byte Raw byte array representing a TCP request.

Returns: - []byte: Processed response as a byte array. Returns an empty response in case of errors.

type Service added in v0.23.24

type Service struct {
	// contains filtered or unexported fields
}

func NewService added in v0.23.24

func NewService(address string, maxConns int) *Service

NewService creates a new service instance. Initializes the service and starts connection cleanup routine.

Parameters: - address: string The TCP address of the server. - maxConns: int Maximum number of connections.

Returns: - *Service: New service instance.

func (*Service) Close added in v0.23.24

func (s *Service) Close() error

Close closes all TCP connections of the service. It stops the cleanup ticker and closes each active connection in the service.

Returns: - error: An error, if any occurred during the closure of connections.

func (*Service) Send added in v0.23.24

func (s *Service) Send(exchange *transport.Exchange) *transport.Exchange

Send sends a request and waits for a response. Uses an available connection from the pool or scales up if needed.

Parameters: - exchange: *transport.Exchange Exchange object with request and response.

Returns: - *transport.Exchange: Updated exchange object with response.

Jump to

Keyboard shortcuts

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