简体   繁体   中英

Communicating between processes on different computers

I wanted to communicate between processes (one process does something, sends results to other process which does something with it). So I used this code:

Server:

from multiprocessing.connection import Listener

address = ('localhost', 6000)     # family is deduced to be 'AF_INET'
listener = Listener(address, authkey='secret password')
conn = listener.accept()
print 'connection accepted from', listener.last_accepted
while True:
    msg = conn.recv()
    # do something with msg
    if msg == 'close':
    conn.close()
    break
listener.close()

Client:

from multiprocessing.connection import Client

address = ('localhost', 6000)
conn = Client(address, authkey='secret password')
conn.send('close')
conn.close()

(source: interprocess communication in python )

And it works like a charm. But I wanted to run these two programs from another computer. On Comp. AI have these 2 programs. I connect to Comp A from Comp B by Wifi Lan (using ssh connection) and I run these 2 programs (which means they're running on Comp A), but they don't connect with each other. I've tried using wifi lan address (192.168.xx) instead of "localhost" but it didn't work neither. What parameter do I have to use instead of "localhost" so that these 2 programs can connect. Or what is the easiest way to do this. Cheers!

Go to command prompt and type ipconfig on the other computer. You need to use the IPv4 address. You also need to make sure the ports are open and ssh enabled. replace the 'localhost' with the IPv4 address.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM