summaryrefslogtreecommitdiffstats
path: root/doc/scriptexamples/socket1.kvs
blob: 382b48c9f52cbf5610d2490b10ab4b56acdb69e3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
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! :)"