python socket usage

Gary Herron gherron at
Thu Aug 16 12:24:21 CEST 2007

Oğuz Yarımtepe wrote:
> On Thursday 16 August 2007 11:20:38 Gary Herron wrote:
>> If you really want to send any Python object through a socket, look up
>> the Pickle and cPickle modules.  These will marshal (as it's called) any
>> Python object of any type and complexity into a byte string which can be
>> sent across a socket.  On the receiving end of the socket, the byte
>> string can be turned back into an equivalent Python object.
>> Gary Herron
> As i read pickle module is Python-spesific. I need to talk with a Java 
> application and get the infortion that it will send. What i do right now is 
> listening a socket and reding the string that is sent by the java 
> application. So the java application is sending a string and i am reading and 
> parsing it and getting the related infortion i need. A more professional way 
> may be the reading the object itself. Is it possible to get the array for ex. 
> object that is sent from the Java application with sockets?
Then consider XMLRPC.  It is a language/platform independent way of
making a call to a remote procedure (with parameters).   Your Python
program would implement a XMLRPC server listening for calls to a single
procedure, and your Java program would make a connection to the XMLRPC
server and make a call to the procedure.

The XMLRPC package in JAVA (don't know what it's called, but it's gotta
exist) will package up the procedure being called and its parameters as
an XML document, and  send it to the server.  The  Python  XMLRPC server
package will decipher the XML document, extracting the procedure name
and its arguments, make the call, and package up any return value (again
as an XML document) and send it back on the socket.  The calling JAVA
program will receive the return value, just as in any normal procedure
call, and continue on it's merry way.

The XMLRPC protocol can only pass simple arguments, and (I think) arrays
of simple arguments.   But that's sufficient for a tuple of integers as
you had in your example.

Hope that helps,
Gary Herron

More information about the Python-list mailing list