Skip to content

Commit

Permalink
Merge 8e77955 into 4e782a6
Browse files Browse the repository at this point in the history
  • Loading branch information
andrehp committed Aug 22, 2018
2 parents 4e782a6 + 8e77955 commit e14b7f6
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 10 deletions.
4 changes: 0 additions & 4 deletions Gopkg.toml
Expand Up @@ -37,10 +37,6 @@
name = "github.com/gorilla/websocket"
version = "1.2.0"

[[constraint]]
name = "github.com/urfave/cli"
version = "1.20.0"

[prune]
go-tests = true
unused-packages = true
Expand Down
38 changes: 32 additions & 6 deletions client/client.go
Expand Up @@ -21,6 +21,7 @@
package client

import (
"crypto/tls"
"encoding/json"
"errors"
"fmt"
Expand Down Expand Up @@ -305,31 +306,56 @@ func (c *Client) Disconnect() {
}
}

// ConnectTo connects to the server at addr, for now the only supported protocol is tcp
// ConnectToTLS connects to the server at addr using TLS, for now the only supported protocol is tcp
// this methods blocks as it also handles the messages from the server
func (c *Client) ConnectTo(addr string) error {
conn, err := net.Dial("tcp", addr)
func (c *Client) ConnectToTLS(addr string, skipVerify bool) error {
conn, err := tls.Dial("tcp", addr, &tls.Config{
InsecureSkipVerify: skipVerify,
})
if err != nil {
return err
}
c.conn = conn
c.IncomingMsgChan = make(chan *message.Message, 10)

err = c.sendHandshakeRequest()
if err != nil {
if err = c.handleHandshake(); err != nil {
return err
}

err = c.handleHandshakeResponse()
c.closeChan = make(chan struct{})
return nil
}

// ConnectTo connects to the server at addr, for now the only supported protocol is tcp
// this methods blocks as it also handles the messages from the server
func (c *Client) ConnectTo(addr string) error {
conn, err := net.Dial("tcp", addr)
if err != nil {
return err
}
c.conn = conn
c.IncomingMsgChan = make(chan *message.Message, 10)

if err = c.handleHandshake(); err != nil {
return err
}

c.closeChan = make(chan struct{})

return nil
}

func (c *Client) handleHandshake() error {
if err := c.sendHandshakeRequest(); err != nil {
return err
}

if err := c.handleHandshakeResponse(); err != nil {
return err
}
return nil
}

// SendRequest sends a request to the server
func (c *Client) SendRequest(route string, data []byte) (uint, error) {
return c.sendMsg(message.Request, route, data)
Expand Down

0 comments on commit e14b7f6

Please sign in to comment.