server

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: May 27, 2018 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Command = cli.Command{
	Name:  "server",
	Usage: "Run a chat server to which clients may connect",
	Flags: []cli.Flag{
		cli.StringFlag{
			Name:  "listen",
			Usage: "The address on which the server should listen",
			Value: "0.0.0.0:2428",
		},
	},
	Action: func(c *cli.Context) error {
		svr, err := newTcpServer(c.String("listen"))
		if err != nil {
			return errors.Wrap(err, "server: failed to start listening")
		}

		shutdownCh := make(chan os.Signal)
		signal.Notify(shutdownCh, syscall.SIGINT, syscall.SIGTERM)

		go func() {
			select {
			case <-shutdownCh:
				svr.Shutdown()
			}
		}()

		return svr.Run()
	},
}

Functions

This section is empty.

Types

type Client

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

func (*Client) Disconnect

func (c *Client) Disconnect() error

func (*Client) Send

func (c *Client) Send(cmd *protocol.RawCommand) error

type Room

type Room struct {
	Clients []*Client
	// contains filtered or unexported fields
}

func (*Room) Broadcast

func (r *Room) Broadcast(cmd *protocol.RawCommand) error

func (*Room) Join

func (r *Room) Join(cl *Client) error

func (*Room) Leave

func (r *Room) Leave(cl *Client) error

type Server

type Server interface {
	GetRoom(id string) *Room
	Broadcast(cmd *protocol.RawCommand) error
	Run() error
	Shutdown() error
}

Jump to

Keyboard shortcuts

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