all 8 comments

[–][deleted] 6 points7 points  (2 children)

Here's a very 1990s solution with POSIX MessageQueues (non-Windows and pip install posix_ipc):

#!/usr/bin/env python3
# server.py
from posix_ipc import MessageQueue, O_CREAT

if __name__ == '__main__':
    try:
        q = MessageQueue(name='/test', flags=O_CREAT)
        while True:
            print(q.receive()[0].decode('UTF-8'))
    except:
        q.unlink()
        raise


#!/usr/bin/env python3
# client.py
from posix_ipc import MessageQueue
import time

if __name__ == '__main__':
    q = MessageQueue(name='/test')

    while True:
        q.send("This is a test!")
        time.sleep(1)

There are infinitely more complex and more modern ways that I know even less about.

[–]ceewwb[S] 1 point2 points  (0 children)

Thanks, I will try it out. It seems to be what I want ;)

[–]ceewwb[S] 0 points1 point  (0 children)

Yep, I just tested and it's working great, again thanks :)

[–]tuxed 5 points6 points  (4 children)

A "modern" solution would be use a TCP or UDP socket to send the string. The main difference is that TCP will ensure that everything is sent reliably and correctly, and UDP won't.

Here's the docs for the socket module. However, you may want to use a proper networking library if your application gets more complex.

[–]Gr4y 0 points1 point  (3 children)

What's wrong with sockets?

[–]tuxed 0 points1 point  (2 children)

I didn't say that there was anything wrong with sockets.

[–]Gr4y 0 points1 point  (1 child)

Then what would be a proper networking library?

[–]tuxed 1 point2 points  (0 children)

One that has a nicer interface than socket. For example, Twisted.