Example #1
0
func NewClientWithAddr(addr string) (*Client, error) {
	c, err := rpcplus.DialHTTP("tcp", addr)
	if err != nil {
		return nil, err
	}
	return newClient(c, addr), nil
}
Example #2
0
func (c *Client) reconnect(disconnectedClient *rpcplus.Client) error {
	if c.addr == "" {
		c.notify(ConnStatusDisconnected)
		return errors.New("no reconnect address set")
	}
	c.clientMtx.Lock()
	defer c.clientMtx.Unlock()
	if disconnectedClient != c.client {
		// another goroutine has already reconnected
		return nil
	}
	c.setReconnecting(true)
	c.notify(ConnStatusDisconnected)
	for {
		if c.isClosed() {
			return ErrDisconnected
		}
		log.Printf("discover: reconnecting to %s", c.addr)
		client, err := rpcplus.DialHTTP("tcp", c.addr)
		if err != nil {
			c.notify(ConnStatusConnectFailed)
			log.Printf("discover: failed to reconnect to %s: %s", c.addr, err)
			time.Sleep(time.Second)
			continue
		}
		log.Printf("discover: reconnected to %s", c.addr)
		c.client = client
		c.setReconnecting(false)
		c.notify(ConnStatusConnected)
		return nil
	}
}
Example #3
0
func (s *S) TestBadAuth(c *C) {
	res, err := http.Get(s.srv.URL + "/apps")
	c.Assert(err, IsNil)
	res.Body.Close()
	c.Assert(res.StatusCode, Equals, 401)

	req, err := http.NewRequest("GET", s.srv.URL+"/apps", nil)
	c.Assert(err, IsNil)
	req.SetBasicAuth("", authKey+"wrong")
	res, err = http.DefaultClient.Do(req)
	c.Assert(err, IsNil)
	res.Body.Close()
	c.Assert(res.StatusCode, Equals, 401)

	_, err = rpcplus.DialHTTP("tcp", s.srv.Listener.Addr().String())
	c.Assert(err, Not(IsNil))
}