-
Notifications
You must be signed in to change notification settings - Fork 0
/
server_test.go
58 lines (45 loc) · 1.02 KB
/
server_test.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
51
52
53
54
55
56
57
58
package eventsocket
import (
"fmt"
"testing"
)
type ServerNooper struct{}
func (n *ServerNooper) OnConnect(con *Connection) {
fmt.Println("Connected")
evt, err := con.Send("event", "plain", "HEARTBEAT")
if err != nil {
fmt.Println("ahn?")
return
}
fmt.Println(evt.Success)
con.Execute(&Command{
App: "answer",
Args: "",
})
}
func (n *ServerNooper) OnDisconnect(con *Connection) {
fmt.Println("disconnect")
}
func (n *ServerNooper) OnEvent(con *Connection, evt *Event) {
fmt.Println("event", evt.EventBody.Get("Event-Name"))
}
func (n *ServerNooper) OnClose(con *Connection) {
fmt.Println("close")
}
func (n *ServerNooper) OnNewConnection(con *Connection) {
fmt.Println("Got new connection")
con.Listener = n
go con.Loop()
}
func Test_Server(t *testing.T) {
fmt.Println("Test Basic Server")
server, err := CreateServer(ServerSettings{
Address: "localhost:8087",
Listener: new(ServerNooper),
})
if err != nil {
fmt.Println("Something went wrong ", err)
}
fmt.Println("Listening")
server.Loop()
}