-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathwebsocket.go
41 lines (36 loc) · 963 Bytes
/
websocket.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
package carrot
import (
"fmt"
"net/url"
"github.com/gorilla/websocket"
)
//unused for later purpose
type completion struct {
body struct {
code string
fileType string
line int
column int
wordToComplete string
offset int
}
}
func getAddr(addr string) string {
return addr
}
// CreateSocket returns a socket instance
func CreateSocket(addr string, urlProto string, path string, counter *Counter) (*websocket.Conn, error) {
wsaddr := url.URL{Scheme: urlProto, Host: getAddr(addr), Path: path}
c, _, err := websocket.DefaultDialer.Dial(wsaddr.String(), nil)
counter.Increment() // increment global counter
if err != nil {
//log.Fatal("dial:", err)
fmt.Println("Broken WebSocket Conn:", counter.val)
counter.Failure()
} else {
fmt.Println("Created WebSocket Conn:", counter.val)
counter.Success()
}
fmt.Println("Success and Failures", counter.success, counter.failure)
return c, err
}