mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Make publishing the content server via mDNS a little more robust
This commit is contained in:
parent
a000a3a2df
commit
7a5e3e8182
@ -146,6 +146,8 @@ Now you should be able to access your books on your iPhone by opening Stanza. Go
|
|||||||
|
|
||||||
Replace ``192.168.1.2`` with the local IP address of the computer running |app|. If you have changed the port the |app| content server is running on, you will have to change ``8080`` as well to the new port. The local IP address is the IP address you computer is assigned on your home network. A quick Google search will tell you how to find out your local IP address. Now click "Save" and you are done.
|
Replace ``192.168.1.2`` with the local IP address of the computer running |app|. If you have changed the port the |app| content server is running on, you will have to change ``8080`` as well to the new port. The local IP address is the IP address you computer is assigned on your home network. A quick Google search will tell you how to find out your local IP address. Now click "Save" and you are done.
|
||||||
|
|
||||||
|
If you get timeout errors while browsing the calibre catalog in Stanza, try increasing the connection timeout value in the stanza settings. Go to Info->Settings and increase the value of Download Timeout.
|
||||||
|
|
||||||
How do I use |app| with my Android phone?
|
How do I use |app| with my Android phone?
|
||||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
|
||||||
|
@ -3,30 +3,40 @@ __license__ = 'GPL 3'
|
|||||||
__copyright__ = '2009, Kovid Goyal <kovid@kovidgoyal.net>'
|
__copyright__ = '2009, Kovid Goyal <kovid@kovidgoyal.net>'
|
||||||
__docformat__ = 'restructuredtext en'
|
__docformat__ = 'restructuredtext en'
|
||||||
|
|
||||||
import socket
|
import socket, time
|
||||||
|
|
||||||
_server = None
|
_server = None
|
||||||
|
|
||||||
def get_external_ip():
|
def _get_external_ip():
|
||||||
'Get IP address of interface used to connect to the outside world'
|
'Get IP address of interface used to connect to the outside world'
|
||||||
try:
|
try:
|
||||||
ipaddr = socket.gethostbyname(socket.gethostname())
|
ipaddr = socket.gethostbyname(socket.gethostname())
|
||||||
except:
|
except:
|
||||||
ipaddr = '127.0.0.1'
|
ipaddr = '127.0.0.1'
|
||||||
if ipaddr == '127.0.0.1':
|
if ipaddr == '127.0.0.1':
|
||||||
|
for addr in ('192.0.2.0', '198.51.100.0', 'google.com'):
|
||||||
try:
|
try:
|
||||||
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
|
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
|
||||||
s.connect(('google.com', 0))
|
s.connect((addr, 0))
|
||||||
ipaddr = s.getsockname()[0]
|
ipaddr = s.getsockname()[0]
|
||||||
except:
|
if ipaddr != '127.0.0.1':
|
||||||
pass
|
|
||||||
return ipaddr
|
return ipaddr
|
||||||
|
except:
|
||||||
|
time.sleep(0.3)
|
||||||
|
return ipaddr
|
||||||
|
|
||||||
|
_ext_ip = None
|
||||||
|
def get_external_ip():
|
||||||
|
global _ext_ip
|
||||||
|
if _ext_ip is None:
|
||||||
|
_ext_ip = _get_external_ip()
|
||||||
|
return _ext_ip
|
||||||
|
|
||||||
def start_server():
|
def start_server():
|
||||||
global _server
|
global _server
|
||||||
if _server is None:
|
if _server is None:
|
||||||
from calibre.utils.Zeroconf import Zeroconf
|
from calibre.utils.Zeroconf import Zeroconf
|
||||||
_server = Zeroconf()
|
_server = Zeroconf(bindaddress=get_external_ip())
|
||||||
return _server
|
return _server
|
||||||
|
|
||||||
def publish(desc, type, port, properties=None, add_hostname=True):
|
def publish(desc, type, port, properties=None, add_hostname=True):
|
||||||
@ -41,8 +51,11 @@ def publish(desc, type, port, properties=None, add_hostname=True):
|
|||||||
'''
|
'''
|
||||||
port = int(port)
|
port = int(port)
|
||||||
server = start_server()
|
server = start_server()
|
||||||
hostname = socket.gethostname().partition('.')[0]
|
|
||||||
if add_hostname:
|
if add_hostname:
|
||||||
|
try:
|
||||||
|
hostname = socket.gethostname().partition('.')[0]
|
||||||
|
except:
|
||||||
|
hostname = 'Unknown'
|
||||||
desc += ' (on %s)'%hostname
|
desc += ' (on %s)'%hostname
|
||||||
local_ip = get_external_ip()
|
local_ip = get_external_ip()
|
||||||
type = type+'.local.'
|
type = type+'.local.'
|
||||||
|
Loading…
x
Reference in New Issue
Block a user