forked from quic-go/quic-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
72 lines (60 loc) · 1.24 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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
package main
import (
"context"
"crypto/tls"
"fmt"
"github.com/PKURio/quic-go"
"github.com/PKURio/quic-go/node"
"io"
"net"
"time"
)
const (
addr = "localhost:4242"
message = "foo\x00bar"
MaxQuicPktSize = 1370
)
func client() error {
tlsConf := &tls.Config{
InsecureSkipVerify: true,
NextProtos: []string{"quic-echo-example"},
}
session, err := quic.DialAddr(addr, tlsConf, nil)
if err != nil {
return err
}
stream, err := session.OpenStreamSync(context.Background())
if err != nil {
return err
}
var cnt uint8 = 0
go func(cntPtr *uint8) {
bufRcv := make([]byte, MaxQuicPktSize)
for {
nLen, err := io.ReadFull(stream, bufRcv)
if err != nil {
fmt.Println("Client receive error: ", err)
}
fmt.Printf("Client receive '%d' bytes, content: '%s'\n", nLen, bufRcv)
//fmt.Println("Client receive ", nLen, " content: ", bufRcv)
*cntPtr++
}
}(&cnt)
bufSend := make([]byte, 10)
copy(bufSend, message)
for {
stream.Write(bufSend)
fmt.Printf("Client write content: '%s'\n", bufSend)
time.Sleep(500 * time.Millisecond)
}
}
func clientStart(conn net.PacketConn) error {
node.Conn = conn
return nil
}
func main() {
err := client()
if err != nil {
fmt.Println("err: ", err)
}
}