Created
April 24, 2014 14:21
-
-
Save AxGord/11256351 to your computer and use it in GitHub Desktop.
Simple work with network. Libs: pony, proto-gen-haxe.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
})); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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