Exemplo n.º 1
0
func Dial(urlStr string, handler MessageHandler) (*Client, *http.Response, error) {
	d := websocket.Dialer{
		HandshakeTimeout: 10 * time.Second,
		ReadBufferSize:   8192,
		WriteBufferSize:  8192,
	}

	wsConn, httpResp, err := d.Dial(urlStr, nil)
	if err != nil {
		return nil, nil, err
	}

	transport := NewTransport(wsConn, handler)

	client := NewClient(transport)

	// Setup default client message handler if one has not been provided
	if client.transport.handler == nil {
		client.transport.handler = &ClientMessageHandler{client}
	}

	// Start read/write pumps
	client.Start()

	return client, httpResp, nil
}
Exemplo n.º 2
0
func Dial(urlStr string) (*NetworkWebSocketClient, *http.Response, error) {
	d := websocket.Dialer{
		HandshakeTimeout: 10 * time.Second,
		ReadBufferSize:   8192,
		WriteBufferSize:  8192,
	}

	wsConn, httpResp, err := d.Dial(urlStr, nil)
	if err != nil {
		return nil, nil, err
	}

	client := NewNetworkWebSocketClient(wsConn)

	// Start read/write pumps
	go client.readPump()
	go client.writePump()

	return client, httpResp, nil
}