Skip to content

Instantly share code, notes, and snippets.

@katafrakt
Last active September 9, 2015 09:09
Show Gist options
  • Save katafrakt/c3d6ce624048a7a710aa to your computer and use it in GitHub Desktop.
Save katafrakt/c3d6ce624048a7a710aa to your computer and use it in GitHub Desktop.
Connect to RethinkDB from D
import std.stdio, std.socket, std.socketstream, std.stream, std.string, std.conv;
import dproto.dproto;
const proto_def = import("ql2.proto");
mixin ProtocolBufferFromString!proto_def;
void main()
{
auto socket = new TcpSocket(AddressFamily.INET);
socket.connect(new InternetAddress("localhost", 28015));
scope(exit) socket.close();
Stream ss = new SocketStream(socket);
VersionDummy vdm;
ss.write(cast(uint) vdm.Version.V0_4);
ss.write(cast(uint) 0);
ss.write(cast(uint) vdm.Protocol.JSON);
char[1024] buffer;
socket.receive(buffer);
if(to!string(buffer[0..7]) == "SUCCESS")
writeln("SUCCESFULLY CONNECTED");
else
writeln(buffer);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment