Internet Modules
Kamaelia.
|-- Internet.
| |-- __init__.py
| |-- socketConstants.py
| |-- TCPServer.py
| |-- TCPClient.py
| |-- ConnectedSocketAdapter.py
| |-- Selector.py
| |-- InternetConnection.py
| `-- InternetHandlingTests.py
These modules provide the basic primitives relating to network handling. Essentially the
purpose of each file defines a basic primitive in a normal network system.
As with the base Kamaelia package, __init__.py is empty and simply exists to allow package import as follows:
Clearly socketConstants.py contains a bunch of common constants - these aren't provided by the socket module and largely cover error conditions, and are defined to increase code readability.
The internet abstraction primitives can divided thus:
- Connection Factories
- TCPServer.py acts as a factory spawning new connections which are handled by their own components and will often have a protocol handler associated with this.
- TCPClient.py also acts as a factory, but only spawns one connected socket. It acts as a data passthrough proxy for the subcomponent.
Neither connection factory directly handles any data to/from a connected socket.
- Specific Socket Handling:
- Multiple socket handling.
- Selector.py is designed for dealing with checking to see if any network connections are active, and which ConnectedSocketAdapters need to be told they can/should attempt to recieve data. When it detects a server socket has a connection ready to be accepted it simply sends a message to a dynamically allocated outbox to send the appropriate TCPServer factory a message to tell it to accept the connection.
In practice server sockets and data sockets are treated pretty much the same way - the difference of interpretation is handled by the socket adaptor or the factory. Whilst it hasn't been written this allows the "select" based implementation of Selector to be replaced by a polling approach without many code changes. (Indeed this could easily be done on the fly)
- Other code:
- InternetConnection.py is legacy code and due to be ditched
- InternetHandlingTests.py is the current test code being used to drive integration between client/server/selector service. This is a relatively complex example:
- It creates a SimpleServer running and EchoProtocol, and a client running an EchoCheckerProtocolComponent, and a TCPClient. The EchoCheckerProtocolComponent is wired in to handle the application communications. The client connects to the server making a complete loop.