Andrew delgadillo
Andrew delgadillo

Reputation: 714

How To Transfer data from a python web application to a java desktop applaction

I want some help on a way to transfer data from a python web application to a java desktop application.

What I am doing is having java listen on a port and receive data. But I have no idea how I would send data from python to an open port on a server.

What my question is how would I send data from a python web app to an open port on a computer. And would there be any problems like data types and any other things?

Upvotes: 0

Views: 796

Answers (3)

sprezzatura
sprezzatura

Reputation: 472

Why not use sockets in python too and send it to the java server. Java does not know that the end client is python, what it reads is just data(bytes). I have done this, and it works seamlessly.

See the python's struct module for more details on converting datatypes

Upvotes: 1

Russ
Russ

Reputation: 11355

This is a really large question as there are many ways to send data back and forth between server (your java app) and client (your python app).

Your situation is not quite clear (what exactly is your "python web application"?), but you may want to look into XML-RPC. XML-RPC is extremely simple to use and set up, and takes care of "problems like data types and any other things". You basically just set up some functions on your server that the client can call, and have python call them. Arguments are neatly wrapped up by teh client and unwrapped by the server. Return values are the same. It is a simple and clean interface.

For python making calls to the server, you want to use the xmlrpclib module.

To set up an XMLRPC server in java, you have many options. I'm not a Java guy, but I'm sure it is quite simple on that side as well.

There are many good xml-rpc tutorials. Here is one that covers client and server in python.

Like I said earlier, there are MANY options available to you. XML-RPC is a good and simple way to get your feet wet, without really limiting you very much (eg: it has built in fault handling).

Good luck!

Upvotes: 3

alphazero
alphazero

Reputation: 27244

If you use a platform independent data format -- xml, json, yaml, ascii txt, ... -- to represent numbers, you have really nothing to worry about.

If you can not afford the inefficiencies of above, then a binary protocol is required.

Java uses network byte ordering (or Big Endian). Python uses the native host byte ordering, OR, you can specify the byte ordering. Here you want to specify Big Endian (sec 7.3.2.1) in writing your numeric data.

Upvotes: 1

Related Questions