summaryrefslogtreecommitdiff
path: root/example
diff options
context:
space:
mode:
authorBenjamin Franzke <benjaminfranzke@googlemail.com>2012-11-08 14:42:38 +0100
committerBenjamin Franzke <benjaminfranzke@googlemail.com>2012-11-08 14:44:23 +0100
commitfa6e98d8ecf58d4ad4144636f58820d9102695c4 (patch)
treeb6b90099193e9fb84acb5222daf4fb78720d4560 /example
parent85a747753b52a47be9c3a9ecf53d1dfd940e36fb (diff)
downloadwbs-fa6e98d8ecf58d4ad4144636f58820d9102695c4.tar.gz
wbs-fa6e98d8ecf58d4ad4144636f58820d9102695c4.tar.bz2
wbs-fa6e98d8ecf58d4ad4144636f58820d9102695c4.zip
Add an example on how to connect, write and read from a socket with GNU Prolog
Diffstat (limited to 'example')
-rw-r--r--example/socket.pl10
1 files changed, 10 insertions, 0 deletions
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).