-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtool.go
More file actions
37 lines (33 loc) · 711 Bytes
/
tool.go
File metadata and controls
37 lines (33 loc) · 711 Bytes
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
package network
func NewClient(address string) ListenTcp {
url := NewUrl(address)
client := Client{}
switch url.Scheme {
case "ws":
client.SetProtocol(&WsProtocol{})
case "text":
client.SetProtocol(&TextProtocol{})
case "pack":
client.SetProtocol(&PackageLenProtocol{})
default:
panic("ws or text")
}
client.SetUrl(url)
return &client
}
func NewServer(address string) ListenTcp {
url := NewUrl(address)
server := Server{}
switch url.Scheme {
case "ws":
server.SetProtocol(&WebsocketProtocol{})
case "text":
server.SetProtocol(&TextProtocol{})
case "pack":
server.SetProtocol(&PackageLenProtocol{})
default:
panic("ws、text、pack")
}
server.SetUrl(url)
return &server
}