-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.go
64 lines (51 loc) · 1.06 KB
/
server.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
59
60
61
62
63
64
package main
import (
"log"
"os"
"time"
qp "github.com/quic-s/quics-protocol"
)
var host string
var port string
func init() {
host = os.Getenv("HOST")
port = os.Getenv("PORT")
}
func RestClientMessage(msgtype string, message []byte) {
// initialize client
quicClient, err := qp.New()
if err != nil {
log.Panicln(err)
}
// start client
err = quicClient.Dial(host + ":" + port)
if err != nil {
log.Panicln(err)
}
// send message to server
quicClient.SendMessage(msgtype, message)
// delay for waiting message sent to server
time.Sleep(3 * time.Second)
quicClient.Close()
}
func RestClientFile(filepath string) {
// initialize client
quicClient, err := qp.New()
if err != nil {
log.Panicln(err)
}
// start client
err = quicClient.Dial(host + ":" + port)
if err != nil {
log.Panicln(err)
}
file, err := os.ReadFile(filepath)
if err != nil {
log.Println(err)
return
}
quicClient.SendFile(LocalAbsToRoot(filepath, getAccelerDir()), file)
// delay for waiting message sent to server
time.Sleep(3 * time.Second)
quicClient.Close()
}