-
Notifications
You must be signed in to change notification settings - Fork 21
/
main.go
50 lines (39 loc) · 1.11 KB
/
main.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
42
43
44
45
46
47
48
49
50
package main
import (
"fmt"
"os"
"text/scanner"
"github.com/sacOO7/socketcluster-client-go/scclient"
)
func onConnect(client scclient.Client) {
fmt.Println("Connected to server")
}
func onDisconnect(client scclient.Client, err error) {
fmt.Printf("Error: %s\n", err.Error())
os.Exit(1)
}
func onConnectError(client scclient.Client, err error) {
fmt.Printf("Error: %s\n", err.Error())
os.Exit(1)
}
func onSetAuthentication(client scclient.Client, token string) {
fmt.Println("Auth token received :", token)
}
func onAuthentication(client scclient.Client, isAuthenticated bool) {
fmt.Println("Client authenticated :", isAuthenticated)
}
func main() {
var reader scanner.Scanner
client := scclient.New("ws://localhost:8000/socketcluster/")
client.SetBasicListener(onConnect, onConnectError, onDisconnect)
client.SetAuthenticationListener(onSetAuthentication, onAuthentication)
client.EnableLogging()
go client.Connect()
fmt.Println("Enter any key to terminate the program")
reader.Init(os.Stdin)
reader.Next()
// os.Exit(0)
}
func start(client scclient.Client) {
// start writing your code from here
}