[Tutor] Turning a "script" into an "application"

Joe Healy joe at omc-international.com.au
Wed Oct 27 08:18:16 CEST 2004


Bill Mill wrote:

>Joe,
>
>Not sure what you mean. In python, sockets send and receive strings.
>If a server has a socket listening on port X, and it associates some
>string with some function call, all it has to do is call that
>function. In pythonish pseudocode:
>
>#######
># Server
>######
>
>actions = {'func1': func1,   #function reference
>        'func2': myfunc2     #another
>        }
>while 1:
>    socket.bind((host, port))
>    socket.listen()
>    while data to read:
>        read data into variable buf
>    actions[buf]()
>
>#######
># Client
>######
>
>socket.connect((server, port))
>socket.send(func_to_perform)
>
>Is this at all what you mean?
>
>  
>
Yes, I did not realise it was so simple. I gather that this will only 
handle one request at a time and not do anything in the mean time, but 
it looks like a good way of communicating between two processes. I have 
a number of programs collecting data from various places and this looks 
like the beginning of a way to keep an eye on them.

Thanks,

Joe Healy



More information about the Tutor mailing list