server

package
v0.0.0-...-f53f79a Latest Latest
Warning

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

Go to latest
Published: Jul 3, 2019 License: MIT Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Server

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

A Server represents a TCP server capable of accepting connections, and pushing them into the Clients() channel.

Underneath the hood, type `Server` uses a net.Listener (of the TCP-variety) to listen for connections, and maintains a channel for errors, as well as a channel for clients.

func New

func New(bind string) (*Server, error)

New instantiates and returns a new server, bound to the `bind` address given. Semantics for `bind` follow those set forth in the `net` package. Calling `New()` does in-fact create a TCP Listener on that address, and returns an error if the address is non-parsable, or the network is not able to be bound.

Otherwise, a server is returned.

func (*Server) Accept

func (s *Server) Accept()

Accept encapsulates the process of accepting new clients to the server.

In the failing case, if an error is returned from attempting to connect to a socket, then the error will be piped up to the Errs() channel, and the connection request will be ignreod.

In the successful case, the client is written to the internal `clients` channel, which is readable from the Clients() method.

Accept runs within its own goroutine.

func (*Server) Clients

func (s *Server) Clients() <-chan *client.Client

Clients returns a read-only channel of *client.Client, written to when a new connection is obtained into the server.

func (*Server) Close

func (s *Server) Close() error

Close closes the network socket, terminating the processof accepting new connections immediately..

func (*Server) Errs

func (s *Server) Errs() <-chan error

Errs returns a read-only channel of `error`s, written to when accepting a socket connection returns an error.

Jump to

Keyboard shortcuts

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