Documente Academic
Documente Profesional
Documente Cultură
Background Basics of Socket Programming ZMQ (Zero Message Queues) Serialization with Google Protocol Buffers
03/01/13
Mandar Kulkarni
Background
Ref: www.jimdevelopment.com
03/01/13
Background
A collection of computers interconnected by a single technology. Two computers are said to be interconnected if they are able to exchange information
C1
Flow of information
C2
03/01/13
Mandar Kulkarni
Background
03/01/13
Mandar Kulkarni
Background
When we transmit a packet into and across the network, we want to make sure that it is transmitted with no errors so we insert the packet in a frame.
03/01/13
Mandar Kulkarni
Background
TCP/IP : A family of protocols TCP Responsible for connection establishment and management and reliable data transport between software processes on devices IP Envelopes and addresses the data Enables the network to read the envelope and forward the data to its destination Defines how much data can fit in a single packet. Other protocols added to TCP/IP suite UDP, SMTP, FTP, HTTP
Mandar Kulkarni 6
03/01/13
Sockets
A socket is the mechanism that most popular operating systems provide to give programs access to the network Endpoint of a communication system
Analogy: Electrical socket Network socket Wire Communication channel Device Network application (say your web browser)
03/01/13
Mandar Kulkarni
Sockets
03/01/13
Mandar Kulkarni
Sockets
Applications
03/01/13
Mandar Kulkarni
Creating Sockets
03/01/13
Mandar Kulkarni
10
03/01/13
Mandar Kulkarni
11
socket()
connect()
dial
read()/write()
talk
close()
hangup
03/01/13
Mandar Kulkarni
12
Ref: learn-networking.com
03/01/13
Mandar Kulkarni
13
Intelligent transport layer with zmq sockets having internal message queuing capability Supports inter process communication as well Supports N to N connection via PUB-SUB, REQ-REP, PUSH-PULL Supported by 30+ languages including C, C+ +, Java, .NET, Python
03/01/13
Mandar Kulkarni
15
Ref: www.zeromq.org
03/01/13
Mandar Kulkarni
16
Ref: www.zeromq.org
03/01/13
Mandar Kulkarni
17
Ref: www.zeromq.org
03/01/13
Mandar Kulkarni
18
When you send data through sockets it must be serialized first Serialization of objects! (An issue in C++)
Problem: Language dependent for encoding and decoding Advantage: No language barrier, supported by large number of languages including C++, java, python
03/01/13
Mandar Kulkarni
19
Create a .proto file Compile using protocol buffer compiler It will generate .pb.cc and .pb.h files (for C++) for you where the all functions required for you to serialize/de-serialize the message are automatically declared and defined The following example is taken from https://developers.google.com/protocolbuffers/docs/overview
Mandar Kulkarni 20
03/01/13
Example of a serialization
Person person; person.set_name("John Doe"); person.set_id(1234); person.set_email("jdoe@example.com"); fstream output("myfile", ios::out | ios::binary); person.SerializeToOstream(&output);
Example of a deserialization
fstream input("myfile", ios::in | ios::binary); Person person; person.ParseFromIstream(&input); cout << "Name: " << person.name() << endl; cout << "E-mail: " << person.email() << endl;
03/01/13
Mandar Kulkarni
22
03/01/13
Mandar Kulkarni
23
03/01/13
Mandar Kulkarni
24
Further Reading
03/01/13
Mandar Kulkarni
25