Skip to content

Instantly share code, notes, and snippets.

@nvsofts
Created September 8, 2014 05:53
Show Gist options
  • Save nvsofts/031497416ec57dc9caf6 to your computer and use it in GitHub Desktop.
Save nvsofts/031497416ec57dc9caf6 to your computer and use it in GitHub Desktop.
import std.stdio;
import std.array;
import std.range;
import msgpack;
import msgpackrpc.client;
import msgpackrpc.server;
struct Test
{
int id;
string str;
}
class Server
{
TCPServer!Server server;
ubyte[] test()
{
immutable size_t N = 4100;
Test result;
result.id = 1234;
result.str = array(repeat('A', N));
ubyte[] r = pack(result);
writeln("len: ", r.length);
return r;
}
}
void doServer()
{
auto s = new Server();
auto server = new TCPServer!(Server)(s);
s.server = server;
server.listen(Endpoint(12345, "127.0.0.1"));
writeln("Starting server...");
server.start();
}
void doClient()
{
auto client = new TCPClient(Endpoint(12345, "127.0.0.1"));
auto j = client.call!(ubyte[])("test");
auto t = j.unpack!Test();
writeln("recv: ", t);
}
void main(string[] args)
{
if (args.length == 2 && args[1] == "server") {
doServer();
}
doClient();
}
{
"name": "test",
"dependencies": {
"msgpack-d": ">=0.9.2",
"msgpack-rpc": ">=0.1.0"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment