~ubuntu-branches/ubuntu/maverick/coherence/maverick

« back to all changes in this revision

Viewing changes to coherence/extern/telepathy/stream.py

  • Committer: Bazaar Package Importer
  • Author(s): Charlie Smotherman
  • Date: 2010-01-02 10:57:15 UTC
  • mfrom: (1.1.7 upstream) (3.2.8 sid)
  • Revision ID: james.westby@ubuntu.com-20100102105715-sghzl2nw4lr5b1ob
Tags: 0.6.6.2-1
*  New  upstream release, summary of changes:
    - adding all necessary files to MANIFEST.in, to compensate for the
      gone 'auto-include-all-files-under-version-control' setuptools
      feature.
    - rearranging genre and genres attribute in DIDLLite - thx Caleb  
    - fix face_path typo, fixes #275.   

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
import socket
 
2
import gobject
 
3
 
 
4
 
 
5
class TrivialStream:
 
6
    def __init__(self, socket_address=None):
 
7
        self.socket_address = socket_address
 
8
 
 
9
    def read_socket(self, s):
 
10
        try:
 
11
            data = s.recv(1024)
 
12
            if len(data) > 0:
 
13
                print "received:", data
 
14
        except socket.error, e:
 
15
            pass
 
16
        return True
 
17
 
 
18
    def write_socket(self, s, msg):
 
19
        print "send:", msg
 
20
        try:
 
21
            s = s.send(msg)
 
22
        except socket.error, e:
 
23
            pass
 
24
        return True
 
25
 
 
26
class TrivialStreamServer(TrivialStream):
 
27
    def __init__(self):
 
28
        TrivialStream.__init__(self)
 
29
        self._socket = None
 
30
 
 
31
    def run(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))
 
36
 
 
37
        self.socket_address = self._socket.getsockname()
 
38
        print "Trivial Server launched on socket", self.socket_address
 
39
        self._socket.listen(1)
 
40
 
 
41
        gobject.timeout_add(1000, self.accept_client, self._socket)
 
42
 
 
43
    def accept_client(self, s):
 
44
        try:
 
45
            s2, addr = s.accept()
 
46
            s2.setblocking(1)
 
47
            s2.setblocking(0.1)
 
48
            self.handle_client(s2)
 
49
            return True
 
50
        except socket.timeout:
 
51
            return True
 
52
 
 
53
    def handle_client(self, s):
 
54
        pass
 
55
 
 
56
class TrivialStreamClient(TrivialStream):
 
57
 
 
58
    def connect(self):
 
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