Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var Command = cli.Command{ Name: "client", Usage: "Run a chat client which will connect to a server", Flags: []cli.Flag{ cli.StringFlag{ Name: "server", Usage: "The address of the server to connect to", Value: "localhost:2428", }, }, Before: func(c *cli.Context) error { if c.NArg() < 1 { return errors.Errorf("you must provide a name") } return nil }, Action: func(c *cli.Context) error { conn, err := net.Dial("tcp", c.String("server")) if err != nil { return errors.Wrap(err, "chat: failed to connect to server") } tr := transports.NewTcpTransport(conn) cl := NewClient(c.Args().First(), tr) defer cl.Disconnect() go func() { logrus.Debug("Reading messages from the client") for msg := range cl.Messages() { logrus.Debug("Printing message from the client") fmt.Printf("[%s]: %s\n", msg.Sender(), msg.Message()) } logrus.Debug("Stopped reading messages from the client") }() scanner := bufio.NewScanner(os.Stdin) logrus.Debug("") for scanner.Scan() { cl.SendMessage(scanner.Text()) } return errors.Wrap(scanner.Err(), "chat: failed to read message") }, }
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client struct { Name string // contains filtered or unexported fields }
func (*Client) Disconnect ¶
func (*Client) Messages ¶
func (c *Client) Messages() <-chan protocol.MessageCommand
func (*Client) SendMessage ¶
Click to show internal directories.
Click to hide internal directories.