| // Copyright 2015 The Vanadium Authors. All rights reserved. |
| // Use of this source code is governed by a BSD-style |
| // license that can be found in the LICENSE file. |
| "github.com/gorilla/websocket" |
| "v.io/x/ref/profiles/internal/lib/tcputil" |
| func Dial(protocol, address string, timeout time.Duration) (net.Conn, error) { |
| then = time.Now().Add(timeout) |
| tcp := mapWebSocketToTCP[protocol] |
| conn, err := net.DialTimeout(tcp, address, timeout) |
| conn.SetReadDeadline(then) |
| if err := tcputil.EnableTCPKeepAlive(conn); err != nil { |
| u, err := url.Parse("ws://" + address) |
| ws, _, err := websocket.NewClient(conn, u, http.Header{}, 4096, 4096) |
| return WebsocketConn(ws), nil |