Tkinter and XML-RPC

M

Mark Bauman

I'm new to Python (C/C++/Delphi background), and so far I'm impressed with
the language, libraries and community. Anyway, I've just started poking
around with Tkinter and I'm wondering if anyone has any tips or caveats on
incorporating an XML-RPC client and server inside a Tkinter app. I have an
application in mind that would primarily be dealing with short string
messages and the occasional jpeg, so I'm wondering about blocking and
threading issues within the confines of the GUI. I'm just starting to dig
into the detailed docs on Tkinter and the XLM-RPC library, but I thought I
would ask since I'm sure that some folks have been there, done that.

Regards,

Mark...
 
R

Roger Binns

Mark said:
I'm new to Python (C/C++/Delphi background), and so far I'm impressed with
the language, libraries and community. Anyway, I've just started poking
around with Tkinter and I'm wondering if anyone has any tips or caveats on
incorporating an XML-RPC client and server inside a Tkinter app. I have an
application in mind that would primarily be dealing with short string
messages and the occasional jpeg, so I'm wondering about blocking and
threading issues within the confines of the GUI. I'm just starting to dig
into the detailed docs on Tkinter and the XLM-RPC library, but I thought I
would ask since I'm sure that some folks have been there, done that.

The main gotcha to worry about is if you will ever need security
for the XML-RPC. It is fairly easy to add password authentication.
It is however very difficult to tunnel it inside SSL unless you
don't care about there being one connection per request (and a
TCP establishment overhead with a SSL establishment as well).

I actually ended up using Paramiko, a Python implementation of
SSH.

Roger
 
E

Etienne Posthumus

I actually ended up using Paramiko, a Python implementation of
SSH.

Hi Roger

That is a good tip, very interesting. Do you mind explaining what you
did further?
Does your server process listen on localhost, and the client then
connects via SSH to the host on which your server process is running? I
was wondering how I would do it, this was one guess.

Nie to know about Paramiko, it looks a little more lightweight than the
SSH that comes with Twisted, if one does not want to go the whole
Twisted route. Curious how much it could be sped up by using OpenSSL
for the crypto operation in stead of PyCrypto.


Etienne Posthumus
Amsterdam, Netherlands
 
R

Roger Binns

Etienne said:
That is a good tip, very interesting. Do you mind explaining what you
did further?

My program (bitpim) manipulates the phonebook, wallpaper, ringtones
etc for US based CDMA cellphones (they behave very differently than
GSM phones used in the rest of the world :).

I wanted the ability to have the program and the phone on different
machines, including over the Internet (which would make development
easier).

I wanted to use XML-RPC to remote the various methods used when
talking to a port (open, close, read, write) as well as some
others I have (list available devices, read until certain criteria
are met). (Using XML-RPC meant I didn't have to reinvent the
wheel).

I wrote a program (named BitFling) that listens (by default on all
interfaces) for incoming connections and obeys commands sent by
XML-RPC. The BitPim program then makes a connection to this and
issues commands. Behind the scenes, everything is wrapped in
classes in BitPim so it can't tell the difference between a local
or remote port, and really doesn't need to care.

For this solution I obvious required security. I use certificates
(self signed) for BitFling with access granted using username
and password combinations. (You also have to list valid source
addresses).

You have to rework the existing XML-RPC client and server classes
to add the HTTP authentication. I then wrapped it all in SSL
using M2Crypto. Unfortunately the existing XML-RPC stuff goes
out of its way to do one transaction per connection. Additionally
M2Crypto doesn't implement the makefile method, which internal
has the same effects as a dup. I tried pretty hard to rework
the code to not rely on dup, not close connections etc, but
never could get everywhere.

Fortunately I found Paramiko and it was really easy to switch
to that. I didn't both with the HTTP layer and just send
the raw output of the XML-RPC encoding. SSH defines authentication
up front, rather than on every transaction like in HTTP. It also
has the idea of multiple named channels.

So I just use a channel named "bitfling" and use regular old
SSH password authentication.
Nie to know about Paramiko, it looks a little more lightweight than the
SSH that comes with Twisted, if one does not want to go the whole
Twisted route.

I really don't like Twisted anyway. My code naturally is
threaded as the device access doesn't have the equivlent of
polling methods. In theory I could run a background thread
that updates something else that emulates polling, but I
far prefer to just directly write the code I want executed
rather than the Twisted approach of giving a list of what
will be executed.
Curious how much it could be sped up by using OpenSSL
for the crypto operation in stead of PyCrypto.

You do know that pyCrypto uses native code? Paramiko
is all Python however. Consequently I don't think
there will be much performance difference between the
two. Paramiko itself is being repeatedly improved and
I think that will give the biggest performance improvements.

Roger
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,043
Latest member
CannalabsCBDReview

Latest Threads

Top