summaryrefslogtreecommitdiffstats
path: root/doc/scriptexamples/socket1.kvs
diff options
context:
space:
mode:
Diffstat (limited to 'doc/scriptexamples/socket1.kvs')
-rw-r--r--doc/scriptexamples/socket1.kvs45
1 files changed, 45 insertions, 0 deletions
diff --git a/doc/scriptexamples/socket1.kvs b/doc/scriptexamples/socket1.kvs
new file mode 100644
index 00000000..382b48c9
--- /dev/null
+++ b/doc/scriptexamples/socket1.kvs
@@ -0,0 +1,45 @@
+# This is a simple socket class to play with from the console
+# It just echoes the events to the console window
+
+class(testsocket,socket)
+{
+ connectEvent()
+ {
+ echo "[$$] Connected to $$->$remoteIp() $$->$remotePort()"
+ }
+
+ disconnectEvent()
+ {
+ echo "[$$] Disconnected ($0-)"
+ }
+
+ connectFailedEvent()
+ {
+ echo "[$$] Connect failed ($0-)"
+ }
+
+ dataAvailableEvent()
+ {
+ echo "[$$] Data: $$->$read()"
+ }
+}
+
+echo "testsocket class installed"
+echo "You can play with it by using:"
+
+echo "/\%X = \$new(testsocket); # To create it"
+echo "/\%X->\$connect(<host>,<port>); # To connect to a host"
+echo "/\%X->\$write(<data>); # To write ASCII data"
+echo "/\%X->\$close(); # To terminate a connection"
+echo "/delete \%X; # To destroy it"
+echo "...."
+echo "Tip: why don't you try to IRC ?"
+echo "The sequence might be something like:"
+echo "/\%X = \$new(testsocket)"
+echo "/\%X->\$connect(<your_irc_server>,6667)"
+echo "/\%X->\$write(\"USER <youruser> <somestring> <somestring> :<realname>\$cr\$lf\")"
+echo "/\%X->\$write(\"NICK <yournick>\$cr\$lf\")"
+echo "/\%X->\$write(\"JOIN #kvirc\$cr\$lf\")"
+echo "/\%X->\$write(\"PRIVMSG #kvirc :Hello IRC-World! :D\$cr\$lf\")"
+echo "...."
+echo "Have fun! :)"