networking

Slut can do a wide range of networking. Most features that are supported by the Twisted networking framework can be used with Slut. Twisted supports UDP as well as TCP networking and even allows you to go deeper in the OSI stack and work with raw Ethernet frames. On top of UDP and TCP, Twisted supports a wide range of protocols, including HTTP, FTP, Jabber, IRC, XMLRPC, SSL/TLS, IMAP, SSH and many more. Twisted is not just a simple add-on to Slut but Twisted's reactor runs Slut's event loop. This means that all the features that come with this reactor are available to Slut applications. Notable are: Scheduling, Threading, Interprocess Communication

Twisted Documentation

Integration with Slut is almost self-evident. The reactor is available and running in every Slut application. One can call methods on it at any time:

def onSetup(self):
    reactor.callLater(3.5, somefunction)

For networking this means that a protocol needs to be defined in a custom class that inherits from some Twisted protocol. This protocol can then be used in a server or client factory that is called on the reactor. For convenience Slut has three classes that attach standard UDP/TCP Clients/Servers to the world (UDP server is simple enough without, see examples):

from slut.net import TcpClient, TcpServer, UdpClient

TcpClient(host, port, Protocol)
TcpServer(port, Protocol)
UdpClient(host, port)
  • host ... ip address or domain of host computer, a string
  • port ... port to connect to or listen for connections, an integer
  • Protocol ... a reference to the protocol class (not an instance of it) that describes what to do when data is received, sent, connection lost/made etc.

Relevant examples: tcp_client.py, tcp_server.py, udp_client.py, udp_server.py, ALL

Interprocess communication

Interprocess communication is very similar to talking to the network. It can be used to run all kinds of programs concurrently in a separate process while keeping a bidirectional communication pipe open. See example for specifics:

ipc_ping.py
Initiated by Stephan Hechenberger
Thanks to CADRE's 103