6
def __init__(self, socket_address=None):
7
self.socket_address = socket_address
9
def read_socket(self, s):
13
print "received:", data
14
except socket.error, e:
18
def write_socket(self, s, msg):
22
except socket.error, e:
26
class TrivialStreamServer(TrivialStream):
28
TrivialStream.__init__(self)
32
self._socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
33
self._socket.setblocking(1)
34
self._socket.settimeout(0.1)
35
self._socket.bind(("127.0.0.1", 0))
37
self.socket_address = self._socket.getsockname()
38
print "Trivial Server launched on socket", self.socket_address
39
self._socket.listen(1)
41
gobject.timeout_add(1000, self.accept_client, self._socket)
43
def accept_client(self, s):
48
self.handle_client(s2)
50
except socket.timeout:
53
def handle_client(self, s):
56
class TrivialStreamClient(TrivialStream):
59
self._socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
60
self._socket.connect(self.socket_address)
61
print "Trivial client connected to", self.socket_address