ktalk is an instant message system written in pure K which consists of a client script and a server script.
The instant server can be started with a default port of 1234:
k instant/server
or with a specified port number:
k instant/server -i 9876
There are two optional command line arguments: the name of the room:
room
and the name of the operator:
oper
The operator can boot clients.
The server maintains state as two lists: a list of clients handles:
Who
and a list of corresponding client names:
Nicks
There is one synchronous entry point:
hi
A client connects with a synchronous call containing his proposed name. If the name is already in use, a guest id is manufactured from his handle. The client's handle and name are appended to the lists, and his approved name is returned. A message is sent to all clients that the new client has connected.
When a client handle closes, the name and handle are removed from the lists, and a message is sent to all clients that the client has disconnected.
If the server closes, the client attempts to reconnect every second.
There is one asynchronous entry point:
msg
The msg function has four arguments:
message fg color bg color name
If the message begins with a slash (/), it is passed to the command processor.
Valid commands are:
/nick [newname] change to [newname] /me [verb-phrase] use indirect speech /boot [name] operator can boot [name]
If name is empty, the message is broadcast to all clients.
If name is non-empty, the message is sent privately to the client with that name, and to the sender.
The standard instant client can be started using defaults:
k instant/client
in which case name = _u, host = `, and port = 1234. or these values can be specified:
k instant/client name host port
e.g.,
k instant/client fred machine.somewhere.com 4567
The host can be a machine name or an ip address.
On start, every second, the client tries to connect to the server. If the server connection closes, the client will try to reconnect to the server every second.
The client window contains six buttons, a form, and an input box.
Online help is popped up by clicking on the "K" on the top left of the window.
the buttons are:
Who Colors Up Down Top Bottom
Who pops up a list of connected names. click on a name to select that client for private messaging; click on a selected name to revert to public messaging.
Colors pops up a color choice window. select a foreground and a background color, or mix custom rgb colors; e.g. 128832.
Up, Down, Top, and Bottom scroll through the list of messages.
To have the window signal arrival of a message, check Beep.
To send a message, type up to a 1000 characters in the input box at the bottom of the window. Messages are wrapped into X positions.
Incoming messages are of three types:
system messages public messages and objects private messages and objects
Public messages are displayed as:
sender>message body
Private messages are displayed as:
sender>recipient message body
To send a private message to XYZ, either select XYZ from the Who list, or enter the message:
>XYZ this is a private message to XYZ
To send an object, enter:
\[k expression]
For example,
\3 4#!12
The label of a literal message always has a black foreground. The label of an object message has a red foreground.
To detach the contents of an object message, click on its label.
To resend the contents of a detached object, click on its label (the script 'K' in the top left corner).
Two commands are supported:
/nick [newname] /me [verb-phrase]
The nick command succeeds if newname is truly a new name.
The me command always succeeds; e.g.,
/me is using ktalk
If the client is started with a port, messages generated in a separate process can be sent via ipc:
k ktalk/client -i 2345
To send a text message:
(`;2345)3:(`In;();:;"send this message")
or to evaluate and send an object:
(`;2345)3:(`In;();:;"\\3 4#!12")
This technique can be used to manufacture 'bots of arbitrary complexity.
Server is running.
Start two clients, exchange messages:
Enter a long message:
Enter a K expression, prefixed by \. Code is broadcast and executed. Click on the label to detach the object:
Edit the object, broadcast the result:
Receive the edited object, click to detach: