Send JSON with Python Socket
I want to share my experience how JSON can be send between Virtual Machines, this mechanism can help you to gather flexibility on VM-to-VM communication in term of object data that need to be shared.
This start from my curiosity about how to make centralized logging related VMs that deployed in one system, can be monitored in one Node (e.g. CPU usage, ssh log in count, last system restart, and etc).
In this practice I use python and ubuntu server as OS. I use two VMs one as Client and one as Server.
On this practice I want to send this following JSON from Client VM to the Server VM.
{"first":"You're", "second":"Awsome!"}
Before start, dont forget to install python depedencies on both VM!
Server Side Python Script
After all set! lets start the server app by these following command
$ python socket_server.py
Client Side Python Script
Please set the server ip address destination with your fit in (e.g. in my case 10.0.0.10 ). Then start the client app by following command.
$ python socket_client.py
Here are the output will be shown on Server side below:
Socket created ...
socket is listening
got connection from ('10.0.0.20', 58485)
Json received --> {"first": "You're", "second": "Awsome!"}
Happy trying!
Hands-on also available on my GitHub.