Introduction to newLISP/The Internet

Most networking tasks are possible with newLISP's networking functions:

base64-dec decode a string from BASE64 format

base64-enc encode a string to BASE64 format

delete-url delete a URL

get-url read a file or page from the web

net-accept accept a new incoming connection

net-close close a socket connection

net-connect connect to a remote host

net-error return the last error

net-eval evaluate expressions on multiple remote newLISP servers

net-interface define the default network interface

net-listen listen for connections to a local socket

net-local local IP and port number for a connection

net-lookup the name for an IP number

net-peek number of characters ready to read

net-peer remote IP and port for a net-connect

net-ping send a ping packet (ICMP echo request) to one or more addresses

net-receive read data on a socket connection

net-receive-from read a UDP datagram on an open connection

net-receive-udp read a UDP datagram on and closes connection

net-select check a socket or list of sockets for status

net-send send data on a socket connection

net-send-to send a UDP datagram on an open connection

net-send-udp send a UDP datagram and closes connection

net-service translate a service name to a port number

net-sessions return a list of currently open connections

post-url post info to a URL address

put-url upload a page to a URL address.

xml-error return last XML parse error

xml-parse parse an XML document

xml-type-tags show or modify XML type tags

With these networking functions you can build all kinds of network-capable applications. With functions like net-eval you can start newLISP as a daemon on a remote computer and then use on a local computer to send newLISP code across the network for evaluation.

The following code implements a simple IRC (Internet Relay Chat) client, and it shows how the basic network functions can be used. The script logs in to the server using the given username, and joins the # newlisp channel. Then the script divides into two threads: the first thread displays any channel activity in a continuous loop, while the second thread waits for input at the console. The only communication between the two threads is through the shared connected flag.