calling server side function
I have a socket set up between a client and server program. Let's say that I serialize (pickle) some data in the client and send it to the server with the intention of calling a function in the server to process the data. How would one execute the function? This is not for a web-based application, BTW -- it's a desktop based application My current thought process is (using a generalized example): I have a list of numbers in the client and want to find the length of the list using the server. There exists a function find_len() in the server code. I have a list of numbers [1,2,3]. On the client side, I create the tuple (find_len, [1,2,3]), and serialize it. I pass this serialized object via a socket to the server, which unpickles it. The server takes the key (find_len) and uses a getattr call to get the find_len function. The server then calls find_len([1,2,3]) to get the sum. def find_len(list_):return Are there better ways of accomplishing this (I'm aware that there are security pitfalls here...) _ Windows 7: It works the way you want. Learn more. http://www.microsoft.com/Windows/windows-7/default.aspx?ocid=PID24727::T:WLMTAGL:ON:WL:en-US:WWL_WIN_evergreen2:102009-- http://mail.python.org/mailman/listinfo/python-list
Re: calling server side function
En Wed, 28 Oct 2009 04:04:50 -0300, Paul Hartley luapyelt...@hotmail.com escribió: I have a socket set up between a client and server program. Let's say that I serialize (pickle) some data in the client and send it to the server with the intention of calling a function in the server to process the data. How would one execute the function? This is not for a web-based application, BTW -- it's a desktop based application My current thought process is (using a generalized example): I have a list of numbers in the client and want to find the length of the list using the server. There exists a function find_len() in the server code. I have a list of numbers [1,2,3]. On the client side, I create the tuple (find_len, [1,2,3]), and serialize it. I pass this serialized object via a socket to the server, which unpickles it. The server takes the key (find_len) and uses a getattr call to get the find_len function. The server then calls find_len([1,2,3]) to get the sum. def find_len(list_):return Are there better ways of accomplishing this (I'm aware that there are security pitfalls here...) xmlrpc does more or less the same thing, but serializing in xml instead of pickling. -- Gabriel Genellina -- http://mail.python.org/mailman/listinfo/python-list
Re: calling server side function
I second the suggestion for XML-RPC... It also solves the security issue in your example, by only exporting functions you specifically register... look at xmlrpclib in the standard python library. On Wed, Oct 28, 2009 at 8:59 AM, Gabriel Genellina gagsl-...@yahoo.com.ar wrote: En Wed, 28 Oct 2009 04:04:50 -0300, Paul Hartley luapyelt...@hotmail.com escribió: I have a socket set up between a client and server program. Let's say that I serialize (pickle) some data in the client and send it to the server with the intention of calling a function in the server to process the data. How would one execute the function? This is not for a web-based application, BTW -- it's a desktop based application My current thought process is (using a generalized example): I have a list of numbers in the client and want to find the length of the list using the server. There exists a function find_len() in the server code. I have a list of numbers [1,2,3]. On the client side, I create the tuple (find_len, [1,2,3]), and serialize it. I pass this serialized object via a socket to the server, which unpickles it. The server takes the key (find_len) and uses a getattr call to get the find_len function. The server then calls find_len([1,2,3]) to get the sum. def find_len(list_): return Are there better ways of accomplishing this (I'm aware that there are security pitfalls here...) xmlrpc does more or less the same thing, but serializing in xml instead of pickling. -- Gabriel Genellina -- http://mail.python.org/mailman/listinfo/python-list -- http://mail.python.org/mailman/listinfo/python-list
Re: calling server side function
Gabriel Genellina gagsl-...@yahoo.com.ar wrote in message news:mailman.2155.1256716617.2807.python-l...@python.org... En Wed, 28 Oct 2009 04:04:50 -0300, Paul Hartley luapyelt...@hotmail.com escribió: I have a socket set up between a client and server program. Let's say that I serialize (pickle) some data in the client and send it to the server with the intention of calling a function in the server to process the data. How would one execute the function? This is not for a web-based application, BTW -- it's a desktop based application My current thought process is (using a generalized example): I have a list of numbers in the client and want to find the length of the list using the server. There exists a function find_len() in the server code. I have a list of numbers [1,2,3]. On the client side, I create the tuple (find_len, [1,2,3]), and serialize it. I pass this serialized object via a socket to the server, which unpickles it. The server takes the key (find_len) and uses a getattr call to get the find_len function. The server then calls find_len([1,2,3]) to get the sum. def find_len(list_):return Are there better ways of accomplishing this (I'm aware that there are security pitfalls here...) xmlrpc does more or less the same thing, but serializing in xml instead of pickling. -- Gabriel Genellina Also, have a look at RPyc. I've been playing with it for a few days and it sounds it may be what you're after. http://rpyc.wikidot.com/ http://www.ibm.com/developerworks/linux/library/l-rpyc/index.html --Tim Arnold -- http://mail.python.org/mailman/listinfo/python-list