[Tutor] sockets

Kent Johnson kent37 at tds.net
Thu May 4 18:41:29 CEST 2006


Matt Richardson wrote:
> I need to send some data, 2 strings and a list, to a remote computer. 
> After thinking about it some last night, it wouldn't be hard to just 
> send it all as a string and then parse it on the receiving end.
> 
> I'm writing a program for work (and for a class project, so no answers!) 
> that will provide some info on the network location of a laptop.  The 
> client will gather IP address, MAC address, and a traceroute dump (the 
> list mentioned above), then send this off to a super simple server that 
> receives the data and puts it in a database.  We've had a few laptops 
> 'disappear' either through theft or people taking them home to do 'work 
> from home' or whatever.  Makes annual inventory a huge pain.

This would be very easy to do with XML-RPC. On the server side, writ a 
function that takes three parameters - the IP address, MAC address, and 
traceroute dump - and saves them to a database. Use SimpleXMLRPCServer 
to expose the function. On the client side, gather the data and use 
xmlrpclib to call the remote function. Easy. Since this function will 
presumably be exposed on the public internet you need to worry about 
security; you should use some kind of authorization. A really simple 
solution would be to add username and password arguments to the function 
you expose.

You could do all this with the socket library but XML-RPC takes care of 
all the details of connections, etc as well as marshalling and 
unmarshalling the data.

Kent



More information about the Tutor mailing list