SlideShare ist ein Scribd-Unternehmen logo
1 von 14
Downloaden Sie, um offline zu lesen
PYClientServer
Python powered Client-Server architecture on
compressed JSON channel
Outline
❖ Intro
❖ Requirements
❖ Architecture
❖ Implementation
❖ Tests
❖ Conclusion
Introduction - 1 of 2
❏ A need: seamless integration using a lightweight data
exchange format
❏ JSON is emerging as the modern de-facto standard data format for
services integration
❏ TCP is a must, it is reliable and can be secure
❏ JSON over TCP is a trustable solution
❏ Why compression? JSON strings are naturally verbose,
but less than XML, so
❏ compression can help in reducing the footprint
❏ bandwidth utilisation can be effectively improved
❏ RTT latency benefits from (much more responsiveness)
Introduction - 2 of 2
❏ And, Python? Well, it is an agile main stream
programming language
❏ very well suited for network communication
❏ very well supported
❏ platform-independent (so, portable solutions)
❏ powerful in string/data processing
❏ ...
❏ PYClientServer represents an attempt to implement a
working example of the previously outlined needs
Requirements
❏ Let’s go through the needs introduced
a. services integration over the network
b. seamless lightweight communication
c. effective bandwidth utilisation
d. easy extensibility
e. rapid development
f. working code to extend for enhancements
❏ Let’s summarize as follows
a. A Server offering a data-centric service
b. A Client asking for the service
c. A flexible Data Model offering
❏ marshalling/unmarshalling facility
❏ compression/decompression facility
Architecture
Client Server
TCP
Channel
Decoder Encoder
Process#1
Thread#1
Process#2
Thread#1
File System
1. JSON request
2. File Reading
3. Text
compression
4. Server
response
5. Decompressed
Text
0101010101
{ GET, 100 }
Implementation - 1 of 5
❏ Key implementation aspects concerning the Server
a. it takes advantage of Python’s powerful network library: 1 server
handler in few LoC
b. it receives text-based request and replies providing compressed data
❏ Let’s have a look at the code
class TCPRequestHandler(SocketServer.BaseRequestHandler):
…
try:
print "[TCPRequestHandler][handle] Connection accepted... processing"
# Reading request (assuming a small amount of bytes)
data = self.request.recv(1024).strip()
# Unmarshall the request
request = Request('', 0)
data = request.from_json(data)
…
Implementation - 2 of 5
# Read lines from a text file
resource = []
resource.append(self.__resourcepath)
resource.append(self.__filename)
testfile = open(''.join(resource), 'r')
# Prepare the response data
response = Data(True, [], 0)
list = testfile.readlines()
response.vector = list
response.nrbytes = len(list)
# Marshall JSON representation
json_str = response.to_json()
c_response = self.__compression.compress(json_str)
start = time.time()
self.request.sendall(c_response)
print "[TCPRequestHandler][handle] Bunch of compressed data sent back!"
end = time.time()
if (self.__isdebug):
print "Delivery::Time Elapsed::", str(end - start)
Implementation - 3 of 5
❏ As already seen in the Server code, system Data Model
is very important, because
a. it allows to seamlessly marshall/unmarshall the data
b. it allows to perform compression/decompression, according to the
communication protocol
class Request(object):
def __init__(self, name, code):
self.name = name
self.code = code
def to_json(self):
self.__dict__['name'] = self.name
self.__dict__['code'] = self.code
return json.dumps(self.__dict__, indent=4)
def from_json(self, sting):
dict = json.loads(sting)
self.__dict__ = dict
Implementation - 4 of 5
class Utility(object):
def compress(self, data):
string = str(data)
return zlib.compress(string, zlib.Z_BEST_COMPRESSION)
def decompress(self, data):
string = str(zlib.decompress(data))
return string
❏ Till now, Server and Data Model have been briefly
discussed, but those are only simple snippets of code
❏ To have a look at the full code of Server and Data Model, check the
project out on GitHub.
Implementation - 5 of 5
❏ Client thread is the most simple entity involved in the
scenario sketched on the architecture, in fact, it acts as
follows
❏ send a pure JSON request (Data Model aids in doing that)
❏ upon a reception of server data, it performs the decompression as
dictated by the defined communication protocol
# Request creation
data = Request('GET', 100)
# Client socket binding
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.connect((self.__serverhost, self.__serverport))
# Sending JSON data over the socket
sock.send(data.to_json())
response = self.__receive_data(sock)
# Treating compressed data
result = self.__compression.decompress(response)
data = Data(False, [], 0)
data.from_json(result)
Tests
❏ Hereafter some screenshots captured during a session
test are proposed
Server-side: it is important to consider how the compression reduces
drastically the dimensions (form 4.2MB to 1MB)
Client-Side: in less than 1 second, the data are received. Afterwards, data
are decompressed and the first line of the document is disaplyed
Conclusion - 1 of 2
❏ Architecting the communication protocol for the service
integration as shown in the architectural sketch, brings
several advantages
a. effective bandwidth utilization: the compression reduces the verbosity
b. much more responsiveness: the entire data frame is trasferred in less
than a second
❏ Python network programming is really powerful: with
few lines of code, the application programmer can
define and deploy a working multithreaded service
❏ JSON format is really amazing to work with in Python:
as shown, with few lines of code, the library makes the
serialization and deserialization a pretty easy job
❏ Despite the simplified snippets presented, in the
previous slides
❏ Client, Server and Data Model have been presented as the three main
entities involved by design, but some other interesting features have to
be discovered
❏ System Architecture has been depicted and, as seen, it is simple but
powerful at the same time: there is the reason to believe that that
Architecture might scale very well
❏ If you want to contribute or to have a deeper look at the
code, do not hesitate to check the project out from
GitHub.
Conclusion - 2 of 2

Weitere ähnliche Inhalte

Andere mochten auch

K-Means Clustering Algorithm - Cluster Analysis | Machine Learning Algorithm ...
K-Means Clustering Algorithm - Cluster Analysis | Machine Learning Algorithm ...K-Means Clustering Algorithm - Cluster Analysis | Machine Learning Algorithm ...
K-Means Clustering Algorithm - Cluster Analysis | Machine Learning Algorithm ...Edureka!
 
Apache Spark & Hadoop : Train-the-trainer
Apache Spark & Hadoop : Train-the-trainerApache Spark & Hadoop : Train-the-trainer
Apache Spark & Hadoop : Train-the-trainerIMC Institute
 
What Is Salesforce CRM? | Salesforce CRM Tutorial For Beginners | Salesforce ...
What Is Salesforce CRM? | Salesforce CRM Tutorial For Beginners | Salesforce ...What Is Salesforce CRM? | Salesforce CRM Tutorial For Beginners | Salesforce ...
What Is Salesforce CRM? | Salesforce CRM Tutorial For Beginners | Salesforce ...Edureka!
 
Big Data in Container; Hadoop Spark in Docker and Mesos
Big Data in Container; Hadoop Spark in Docker and MesosBig Data in Container; Hadoop Spark in Docker and Mesos
Big Data in Container; Hadoop Spark in Docker and MesosHeiko Loewe
 
Logistic regression
Logistic regressionLogistic regression
Logistic regressionsaba khan
 
Hadoop 2.0 Architecture | HDFS Federation | NameNode High Availability |
Hadoop 2.0 Architecture | HDFS Federation | NameNode High Availability | Hadoop 2.0 Architecture | HDFS Federation | NameNode High Availability |
Hadoop 2.0 Architecture | HDFS Federation | NameNode High Availability | Edureka!
 
Transitioning Compute Models: Hadoop MapReduce to Spark
Transitioning Compute Models: Hadoop MapReduce to SparkTransitioning Compute Models: Hadoop MapReduce to Spark
Transitioning Compute Models: Hadoop MapReduce to SparkSlim Baltagi
 
Online Voting System Project File
Online Voting System Project FileOnline Voting System Project File
Online Voting System Project FileNitin Bhasin
 

Andere mochten auch (12)

Online Voting System
Online Voting SystemOnline Voting System
Online Voting System
 
Apache Spark & Hadoop
Apache Spark & HadoopApache Spark & Hadoop
Apache Spark & Hadoop
 
K-Means Clustering Algorithm - Cluster Analysis | Machine Learning Algorithm ...
K-Means Clustering Algorithm - Cluster Analysis | Machine Learning Algorithm ...K-Means Clustering Algorithm - Cluster Analysis | Machine Learning Algorithm ...
K-Means Clustering Algorithm - Cluster Analysis | Machine Learning Algorithm ...
 
Apache Spark & Hadoop : Train-the-trainer
Apache Spark & Hadoop : Train-the-trainerApache Spark & Hadoop : Train-the-trainer
Apache Spark & Hadoop : Train-the-trainer
 
What Is Salesforce CRM? | Salesforce CRM Tutorial For Beginners | Salesforce ...
What Is Salesforce CRM? | Salesforce CRM Tutorial For Beginners | Salesforce ...What Is Salesforce CRM? | Salesforce CRM Tutorial For Beginners | Salesforce ...
What Is Salesforce CRM? | Salesforce CRM Tutorial For Beginners | Salesforce ...
 
Big Data in Container; Hadoop Spark in Docker and Mesos
Big Data in Container; Hadoop Spark in Docker and MesosBig Data in Container; Hadoop Spark in Docker and Mesos
Big Data in Container; Hadoop Spark in Docker and Mesos
 
Logistic Regression Analysis
Logistic Regression AnalysisLogistic Regression Analysis
Logistic Regression Analysis
 
Logistic regression
Logistic regressionLogistic regression
Logistic regression
 
Hadoop 2.0 Architecture | HDFS Federation | NameNode High Availability |
Hadoop 2.0 Architecture | HDFS Federation | NameNode High Availability | Hadoop 2.0 Architecture | HDFS Federation | NameNode High Availability |
Hadoop 2.0 Architecture | HDFS Federation | NameNode High Availability |
 
Transitioning Compute Models: Hadoop MapReduce to Spark
Transitioning Compute Models: Hadoop MapReduce to SparkTransitioning Compute Models: Hadoop MapReduce to Spark
Transitioning Compute Models: Hadoop MapReduce to Spark
 
Online Voting System Project File
Online Voting System Project FileOnline Voting System Project File
Online Voting System Project File
 
Apache Spark Architecture
Apache Spark ArchitectureApache Spark Architecture
Apache Spark Architecture
 

Kürzlich hochgeladen

WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure servicePooja Nehwal
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Igalia
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxOnBoard
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...shyamraj55
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Alan Dix
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Paola De la Torre
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitecturePixlogix Infotech
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationRidwan Fadjar
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 3652toLead Limited
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersThousandEyes
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 

Kürzlich hochgeladen (20)

WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptx
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC Architecture
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 

PyClientServer: a Python powererd Client-Server Architecture over a compressed JSON/TCP channel

  • 1. PYClientServer Python powered Client-Server architecture on compressed JSON channel
  • 2. Outline ❖ Intro ❖ Requirements ❖ Architecture ❖ Implementation ❖ Tests ❖ Conclusion
  • 3. Introduction - 1 of 2 ❏ A need: seamless integration using a lightweight data exchange format ❏ JSON is emerging as the modern de-facto standard data format for services integration ❏ TCP is a must, it is reliable and can be secure ❏ JSON over TCP is a trustable solution ❏ Why compression? JSON strings are naturally verbose, but less than XML, so ❏ compression can help in reducing the footprint ❏ bandwidth utilisation can be effectively improved ❏ RTT latency benefits from (much more responsiveness)
  • 4. Introduction - 2 of 2 ❏ And, Python? Well, it is an agile main stream programming language ❏ very well suited for network communication ❏ very well supported ❏ platform-independent (so, portable solutions) ❏ powerful in string/data processing ❏ ... ❏ PYClientServer represents an attempt to implement a working example of the previously outlined needs
  • 5. Requirements ❏ Let’s go through the needs introduced a. services integration over the network b. seamless lightweight communication c. effective bandwidth utilisation d. easy extensibility e. rapid development f. working code to extend for enhancements ❏ Let’s summarize as follows a. A Server offering a data-centric service b. A Client asking for the service c. A flexible Data Model offering ❏ marshalling/unmarshalling facility ❏ compression/decompression facility
  • 6. Architecture Client Server TCP Channel Decoder Encoder Process#1 Thread#1 Process#2 Thread#1 File System 1. JSON request 2. File Reading 3. Text compression 4. Server response 5. Decompressed Text 0101010101 { GET, 100 }
  • 7. Implementation - 1 of 5 ❏ Key implementation aspects concerning the Server a. it takes advantage of Python’s powerful network library: 1 server handler in few LoC b. it receives text-based request and replies providing compressed data ❏ Let’s have a look at the code class TCPRequestHandler(SocketServer.BaseRequestHandler): … try: print "[TCPRequestHandler][handle] Connection accepted... processing" # Reading request (assuming a small amount of bytes) data = self.request.recv(1024).strip() # Unmarshall the request request = Request('', 0) data = request.from_json(data) …
  • 8. Implementation - 2 of 5 # Read lines from a text file resource = [] resource.append(self.__resourcepath) resource.append(self.__filename) testfile = open(''.join(resource), 'r') # Prepare the response data response = Data(True, [], 0) list = testfile.readlines() response.vector = list response.nrbytes = len(list) # Marshall JSON representation json_str = response.to_json() c_response = self.__compression.compress(json_str) start = time.time() self.request.sendall(c_response) print "[TCPRequestHandler][handle] Bunch of compressed data sent back!" end = time.time() if (self.__isdebug): print "Delivery::Time Elapsed::", str(end - start)
  • 9. Implementation - 3 of 5 ❏ As already seen in the Server code, system Data Model is very important, because a. it allows to seamlessly marshall/unmarshall the data b. it allows to perform compression/decompression, according to the communication protocol class Request(object): def __init__(self, name, code): self.name = name self.code = code def to_json(self): self.__dict__['name'] = self.name self.__dict__['code'] = self.code return json.dumps(self.__dict__, indent=4) def from_json(self, sting): dict = json.loads(sting) self.__dict__ = dict
  • 10. Implementation - 4 of 5 class Utility(object): def compress(self, data): string = str(data) return zlib.compress(string, zlib.Z_BEST_COMPRESSION) def decompress(self, data): string = str(zlib.decompress(data)) return string ❏ Till now, Server and Data Model have been briefly discussed, but those are only simple snippets of code ❏ To have a look at the full code of Server and Data Model, check the project out on GitHub.
  • 11. Implementation - 5 of 5 ❏ Client thread is the most simple entity involved in the scenario sketched on the architecture, in fact, it acts as follows ❏ send a pure JSON request (Data Model aids in doing that) ❏ upon a reception of server data, it performs the decompression as dictated by the defined communication protocol # Request creation data = Request('GET', 100) # Client socket binding sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) sock.connect((self.__serverhost, self.__serverport)) # Sending JSON data over the socket sock.send(data.to_json()) response = self.__receive_data(sock) # Treating compressed data result = self.__compression.decompress(response) data = Data(False, [], 0) data.from_json(result)
  • 12. Tests ❏ Hereafter some screenshots captured during a session test are proposed Server-side: it is important to consider how the compression reduces drastically the dimensions (form 4.2MB to 1MB) Client-Side: in less than 1 second, the data are received. Afterwards, data are decompressed and the first line of the document is disaplyed
  • 13. Conclusion - 1 of 2 ❏ Architecting the communication protocol for the service integration as shown in the architectural sketch, brings several advantages a. effective bandwidth utilization: the compression reduces the verbosity b. much more responsiveness: the entire data frame is trasferred in less than a second ❏ Python network programming is really powerful: with few lines of code, the application programmer can define and deploy a working multithreaded service ❏ JSON format is really amazing to work with in Python: as shown, with few lines of code, the library makes the serialization and deserialization a pretty easy job
  • 14. ❏ Despite the simplified snippets presented, in the previous slides ❏ Client, Server and Data Model have been presented as the three main entities involved by design, but some other interesting features have to be discovered ❏ System Architecture has been depicted and, as seen, it is simple but powerful at the same time: there is the reason to believe that that Architecture might scale very well ❏ If you want to contribute or to have a deeper look at the code, do not hesitate to check the project out from GitHub. Conclusion - 2 of 2