Changeset b5833c5654f5adca96495c030b1609efb4e5f57f

Show
Ignore:
Timestamp:
12/30/07 23:30:27 (1 year ago)
Author:
Jason Michalski <armooo@armooo.net>
git-committer:
Jason Michalski <armooo@armooo.net> 1199079027 -0600
git-parent:

[00f2d9469dfe9bce49996e55c691e2a1a23051bb]

git-author:
William McBrine <wmcbrine@gmail.com> 1198986350 -0500
Message:

Added the ability to listen for/send beacons on TCP port 2190, for use with the manual server menu. (Use "beacon = listen" in pyTivo.conf to listen only, or "beacon = 255.255.255.255 listen" (or whatever) to both broadcast and listen. With no beacon keyword, no listening occurs.)

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • beacon.py

    r00f2d94 rb5833c5  
    1616        return ';'.join(self.services) 
    1717 
    18     def format_beacon(self): 
     18    def format_beacon(self, conntype): 
    1919        beacon = [] 
    2020 
     
    2323        beacon.append('tivoconnect=1') 
    2424        beacon.append('swversion=1') 
    25         beacon.append('method=broadcast'
     25        beacon.append('method=%s' % conntype
    2626        beacon.append('identity=%s' % guid) 
    2727 
     
    3535        beacon_ips = config.getBeaconAddresses() 
    3636        for beacon_ip in beacon_ips.split(): 
    37             try: 
    38                 self.UDPSock.sendto(self.format_beacon(), (beacon_ip, 2190)) 
    39             except error, e: 
    40                 print e 
    41                 pass 
     37            if beacon_ip != 'listen': 
     38                try: 
     39                    self.UDPSock.sendto(self.format_beacon('broadcast'), 
     40                                        (beacon_ip, 2190)) 
     41                except error, e: 
     42                    print e 
    4243 
    4344    def start(self): 
     
    4950        self.timer.cancel() 
    5051 
     52    def listen(self): 
     53        """For the direct-connect, TCP-style beacon""" 
     54        import thread 
     55 
     56        def server(): 
     57            import struct 
     58 
     59            TCPSock = socket(AF_INET, SOCK_STREAM) 
     60            TCPSock.bind(('', 2190)) 
     61            TCPSock.listen(5) 
     62 
     63            while True: 
     64                # Wait for a connection 
     65                client, address = TCPSock.accept() 
     66 
     67                # Accept the client's beacon 
     68                client_length = struct.unpack('!I', client.recv(4))[0] 
     69                client_message = client.recv(client_length) 
     70 
     71                print client_length 
     72 
     73                # Send ours 
     74                message = self.format_beacon('connected') 
     75                client.send(struct.pack('!I', len(message))) 
     76                client.send(message) 
     77                client.close() 
     78 
     79        thread.start_new_thread(server, ()) 
     80 
    5181if __name__ == '__main__': 
    5282    b = Beacon() 
    5383 
    54  
    5584    b.add_service('TiVoMediaServer:9032/http') 
    56     b.send_beacon_timer() 
     85    b.send_beacon() 
  • pyTivo.py

    r8698247 rb5833c5  
    11#!/usr/bin/env python 
    22 
    3  
    43import beacon, httpserver, os, sys 
    5  
    64import config 
    75 
     
    1614b.add_service('TiVoMediaServer:' + str(port) + '/http') 
    1715b.start() 
     16if 'listen' in config.getBeaconAddresses(): 
     17    b.listen() 
    1818 
    1919try: 
     
    2121except KeyboardInterrupt: 
    2222    b.stop() 
    23