Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The way Firefox does it is: the first instance creates a socket file (or a named pipe on Windows). This serves both as a way for the next instances of Firefox to detect and communicate with the first instance, and forward it the URL before dying. A socket file or named pipe being only accessible from processes running on the local system (as files are), no network client can have access to it. As they are files, firewalls will not block them either (it's like writing on a file).</p> <p>Here is a naive implementation to illustrate my point. On first launch, the socket file <code>lock.sock</code> is created. Further launches of the script will detect the lock and send the URL to it:</p> <pre><code>import socket import os SOCKET_FILENAME = 'lock.sock' def server(): print 'I\'m the server, creating the socket' s = socket.socket(socket.AF_UNIX, socket.SOCK_DGRAM) s.bind(SOCKET_FILENAME) try: while True: print 'Got a URL: %s' % s.recv(65536) except KeyboardInterrupt, exc: print 'Quitting, removing the socket file' s.close os.remove(SOCKET_FILENAME) def client(): print 'I\'m the client, opening the socket' s = socket.socket(socket.AF_UNIX, socket.SOCK_DGRAM) s.connect(SOCKET_FILENAME) s.send('http://stackoverflow.com') s.close() def main(): if os.path.exists(SOCKET_FILENAME): try: client() except (socket.error): print "Bad socket file, program closed unexpectedly?" os.remove(SOCKET_FILENAME) server() else: server() main() </code></pre> <p>You should implement a proper protocol (send proper datagrams instead of hardcoding the length for instance), maybe using <a href="http://docs.python.org/library/socketserver.html" rel="nofollow">SocketServer</a>, but this is beyond this question. The <a href="http://docs.python.org/howto/sockets.html" rel="nofollow">Python Socket Programming Howto</a> might also help you. I have no Windows machine available, so I cannot confirm that it works on that platform.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload