-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathclient.go
More file actions
50 lines (45 loc) · 921 Bytes
/
client.go
File metadata and controls
50 lines (45 loc) · 921 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
38
39
40
41
42
43
44
45
46
47
48
49
50
// client
package main
import (
"code.google.com/p/goprotobuf/proto"
"fmt"
"math/rand"
"msgproto"
"net"
"sync"
"time"
)
func main() {
var wg sync.WaitGroup
fmt.Println("Start")
for i := 0; i < 10; i++ {
wg.Add(1)
go send_data(create_message(), wg)
}
wg.Wait()
}
func create_message() []byte {
ProtoMessage := new(msgproto.Msg)
ProtoMessage.Id = proto.Int32(int32(rand.Intn(1000)))
ProtoMessage.Lat = proto.Int64(int64(rand.Intn(1000)))
ProtoMessage.Long = proto.Int64(int64(rand.Intn(1000)))
ProtoMessage.Utime = proto.Int64((time.Now().Unix()))
data, err := proto.Marshal(ProtoMessage)
if err != nil {
fmt.Println(err)
}
return data
}
func send_data(data []byte, wg sync.WaitGroup) {
fmt.Println("Data")
conn, err := net.Dial("tcp", "localhost:8090")
if err != nil {
fmt.Println(err)
}
n, err := conn.Write(data)
if err != nil {
fmt.Println(err)
}
fmt.Println(n)
wg.Done()
}