From fa6e98d8ecf58d4ad4144636f58820d9102695c4 Mon Sep 17 00:00:00 2001 From: Benjamin Franzke Date: Thu, 8 Nov 2012 14:42:38 +0100 Subject: Add an example on how to connect, write and read from a socket with GNU Prolog --- example/socket.pl | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 example/socket.pl diff --git a/example/socket.pl b/example/socket.pl new file mode 100644 index 0000000..41f87d7 --- /dev/null +++ b/example/socket.pl @@ -0,0 +1,10 @@ +start:-start(localhost). +start(Host):-start(Host, 8068). + +start(Host,Port):- +socket('AF_INET', Socket), +hostname_address(Host, HostAddress), +socket_connect(Socket, 'AF_INET'(HostAddress, Port), StreamIn, StreamOut), +write(StreamOut, c), flush_output(StreamOut), +read_atom(StreamIn, X), write(X), nl, +socket_close(Socket). -- cgit