Skip to content

Instantly share code, notes, and snippets.

@AxGord
Created April 24, 2014 14:21
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AxGord/11256351 to your computer and use it in GitHub Desktop.
Save AxGord/11256351 to your computer and use it in GitHub Desktop.
Simple work with network. Libs: pony, proto-gen-haxe.
import pony.net.Protobuf;
import pony.net.SocketClient;
import pony.net.SocketServer;
import test.Main_Builder;
import test.Sub_Builder;
class ProtoTest {
static function main() {
var serv = new SocketServer(6001);
var server = new Protobuf<Main_Builder, Main_Builder>(serv, test.Main_Writer.writeTo, test.Main_Merger.mergeFrom);
var client = new Protobuf<Main_Builder, Main_Builder>(new SocketClient(6001), test.Main_Writer.writeTo, test.Main_Merger.mergeFrom);
client.onData.add(function(b:Main_Builder) {
trace(b.a);//=> 3
trace(b.b);//=> 5
trace(b.sub.a);//=> 7
trace(b.sub.b);//=> 9
});
serv.connect.add(server.send.bind(function(b) {
b.a = 3;
b.b = 5;
b.sub = new Sub_Builder();
b.sub.a = 7;
b.sub.b = 9;
}));
}
}
package test;
message Main {
optional int32 a = 1;
optional int32 b = 2;
optional Sub sub = 3;
}
message Sub {
optional int32 a = 1;
optional int32 b = 2;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment