Skip to content

Commit e703e89

Browse files
committed
basic Go client
1 parent c0c8363 commit e703e89

File tree

5 files changed

+34
-6
lines changed

5 files changed

+34
-6
lines changed

C++/src/client_sync.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ int main() {
1414

1515
socket.connect(boost::asio::local::stream_protocol::endpoint(ADDRESS));
1616

17-
asio::Boring msg;
17+
example_mess::Boring msg;
1818
msg.set_cont("Greetings from CPP-land!");
1919

2020

C++/src/server_async.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ class handler: public asio_handler<handler> {
3232
void handle_message(const boost::system::error_code& error) {
3333
if(error) {cerr << error.message() << endl; return;}
3434

35-
asio::Boring msg;
35+
example_mess::Boring msg;
3636
bool r = msg.ParseFromArray(message.data(), message.size());
3737
if(!r) {
3838
cerr << "Failed parsing" << endl;

C++/src/server_sync.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ class handler: public asio_handler<handler> {
3030
message.resize(message_length);
3131
boost::asio::read(socket_, boost::asio::buffer(message));
3232

33-
asio::Boring msg;
33+
example_mess::Boring msg;
3434
bool r = msg.ParseFromArray(message.data(), message.size());
3535
if(!r) {
3636
cerr << "Failed parsing" << endl;

Go/src/client/main.go

+31-2
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,46 @@ package main
22

33
import (
44
"log"
5+
"net"
6+
//"fmt"
7+
//"bytes"
8+
"encoding/binary"
59

610
"code.google.com/p/goprotobuf/proto"
711
"example_mess"
812
)
913

14+
var _ = net.Dial
15+
//var _ = bytes.Buffer
16+
1017
func main() {
18+
19+
socket, err := net.Dial("unix", "socket")
20+
if err!= nil {
21+
log.Fatal("Failed to connect to socket: ", err)
22+
}
23+
24+
defer socket.Close()
25+
1126
test := &example_mess.Boring {
12-
Cont: proto.String("wew"),
27+
Cont: proto.String("Greets from Go"),
1328
}
14-
_, err := proto.Marshal(test)
29+
serialized, err := proto.Marshal(test)
1530
if err != nil {
1631
log.Fatal("marshaling error: ", err)
1732
}
33+
34+
35+
//buf := new(bytes.Buffer)
36+
println(len(serialized))
37+
//err = binary.Write(buf, binary.BigEndian, int32(1337))
38+
//fmt.Printf("% d", buf.Bytes())
39+
40+
// Go is unique in that, thanks to its interfaces, it's practical to encode directly to the socket
41+
err = binary.Write(socket, binary.BigEndian, int32(len(serialized)))
42+
if err != nil {
43+
log.Fatal("failed writing to socket: ", err)
44+
}
45+
46+
socket.Write(serialized)
1847
}

makefile

-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ $(GO_BINS): %: Go/src/%/main.go Go/src/example_mess/msg.pb.go Go/src/code.google
3737

3838
Go/src/example_mess/msg.pb.go: msg.proto
3939
protoc --go_out=Go/src/example_mess msg.proto
40-
#GOPATH=$(CURDIR)/Go go install pb_message
4140

4241
Go/src/code.google.com/p/goprotobuf:
4342
GOPATH=$(CURDIR)/Go go get code.google.com/p/goprotobuf/proto

0 commit comments

Comments
 (0)