Last active
September 9, 2015 09:09
-
-
Save katafrakt/c3d6ce624048a7a710aa to your computer and use it in GitHub Desktop.
Connect to RethinkDB from D
This file contains 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 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