OpenCV 2 Boost v1.66+ Qt 5.12.6
- Khaled Soliman
- Mohamed Ads
- Khloud Ghattas
- Ahmed
Distributed-Systems-Fall19 project
License: MIT License
Marshaling and unMarshalling of messages between the client and the server
The client and the server programs should be built on top of an OO class hierarchy, which utilizes sockets and concurrency primitives.
The UDPSocket class encapsulates all the data and methods necessary to establish communication between two entities. This class acts as a parent class to the UDPClientSocket and the UDPServerSocket. Notice the wealth of methods for reading and writing from a UDP socket with different timeout options.
UDPSOCKET_H
#define UDPSOCKET_H
class UDPSocket
{
protected:
int sock;
sockaddr_in myAddr; sockaddr_in peerAddr; char * myAddress;
char * peerAddress;
int myPort;
int peerPort;
bool enabled; pthread_mutex_t mutex;
public:
UDPSocket ();
void setFilterAddress (char * _filterAddress);
char * getFilterAddress ();
bool initializeServer (char * _myAddr, int _myPort); bool initializeClient (char * _peerAddr, int _peerPort);
int writeToSocket (char * buffer, int maxBytes );
int writeToSocketAndWait (char * buffer, int maxBytes,int microSec );
int readFromSocketWithNoBlock (char * buffer, int maxBytes );
int readFromSocketWithTimeout (char * buffer, int maxBytes, int timeoutSec, int timeoutMilli); int readFromSocketWithBlock (char * buffer, int maxBytes );
int readSocketWithNoBlock (char * buffer, int maxBytes );
int readSocketWithTimeout (char * buffer, int maxBytes, int timeoutSec, int timeoutMilli);
int readSocketWithBlock (char * buffer, int maxBytes );
int getMyPort ();
int getPeerPort ();
void enable();
void disable();
bool isEnabled();
void lock();
void unlock();
int getSocketHandler();
~UDPSocket ( );
};
#endif // UDPSOCKET_H
This class encapsulates the state of the message to be sent between a client and a server. Notice the method “marshal” which converts the data members of an object instantiated from this class to a data stream. I recommend using a data stream format that avoids the null character as you may send binary data; a good candidate for that is the base64 format, and you can read about the base64 encode and decode here http://en.wikipedia.org/wiki/Base64. Of course there are other alternatives that you can use but you need to be very careful and have very good reasons for your choice.
The “unmarshalling” is carried out via the second parameterized constructor, which receives a base64 formatted character array. In exercise 1 you will not need to utilize the “operation” and “rpc_id” data members but they will be needed in the next phases of the project. The message type should be set by the client and the server objects whose class definitions are presented below. For exercise 2 you will definitely need to extend this class either through inheritance of through amendment to account for other data attributes of the media file to be transferred such as file name, file attributes, storage location, etc.
#ifndef MESSAGE_H #define MESSAGE_H
enum MessageType { Request, Reply}; class Message
{
private:MessageType message_type; int operation;
void * message; size_t message_size; int rpc_id;
public:Message(int operation, void * p_message, size_t p_message_size,int p_rpc_id); Message(char * marshalled_base64);
char * marshal ();
int getOperation ();
ing getRPCId();
void * getMessage();
size_t getMessageSize();
MessageType getMessageType();
void setOperation (int _operation);
void setMessage (void * message, size_t message_size); void setMessageType (MessageType message_type); ~Message();
};
#endif // MESSAGE_H
Useful Resources
To help you start with Linux, we have compiled a list of Linux resources that would help take you from novice stage to Kernel expert (as needed). The list is the work of the very large community of people who have worked with the Linux kernel.
For Starters
♦ Kernel Newbies: Intended to help new kernel hackers
♦ Linux Questions: A civil forum asking linux questions
♦ Ubuntu Support Forums: From the best-known consumer distribution of Linux, including a section for absolute beginners
Kernel News
• Linux Weekly News (LWN.net) Kernel Hacking
• Here is where you can get any kernel you want: Linux Kernel Archives at kernel.org
• The Linux Kernel Documentation Project
• The Linux Kernel by David A Rusling
• Linux Kernel Internals by Tigran Aivazian
• The Linux Kernel Hackers' Guide: HTML Linux Kernel Debuggers
• KDB: built-in kernel debugger with multiprocessor support
• Kgdb: kernel debugger used through serial line
Source Navigators
The source navigators provide browse-able kernel code, making it easier to read than your ssh window or emacs. However, the kernel is not necessarily the same version as the kernel you will be working with, so watch out for subtle differences.
• Linux Source Navigator
• Another Linux Source Navigator
Steganography
• http://en.wikipedia.org/wiki/Steganography
• http://easybmp.sourceforge.net/steganography.html
• http://manytools.org/hacker-tools/steganography-encode-text-into-image/
• http://www.maketecheasier.com/hide-confidential-data-inside-images-in-linux/
• http://www.findbestopensource.com/tagged/Steganography
• http://punkroy.drque.net/PNG_Steganography/SteganographyC.php
C Language Resources
As Linux is written mostly in C, if you are unfamiliar with the language, we provide you with few links that will jump-start your C capabilities in no time.
• C programming.com
• ANSI C On Unix Systems
• Common C Problems
• C Frequently Asked Questions
• This includes a tutorial and full reference to C: Programming In C: Unix System Calls and Subroutines in C
Client: this takes the name of the server computer as an argument (i.e. at the command line).
The Client class encapsulates the client functionalities. It has an instance of the UDPClientSocket class, which implements the UDP client. The constructor receives the host name that the server process resides on as well as the port number. The execute method receives a message which is transmitted for remote execution, and the reply message is returned. Prior to sending the request, the message type should be set as a “Request”. The type of the message received as a reply should be checked and its type should be a “Reply”. All the network operations details should be encapsulated inside the execute method, and the calling routine should not be aware of the remote execution.
#ifndef CLIENT_H #define CLIENT_H
class Client
{
private:
UDPClientSocket * udpSocket;
public:
Client(char * _hostname, int _port); Message * execute(Message * _message); ~Client();
};
#endif // CLIENT_H
This class represents a client UDP socket and it inherits from theUDPSocket class. It has an initialization method that initializes the UDPSocket in a client mode.
#ifndef UDPCLIENTSOCKET_H #define UDPCLIENTSOCKET_H
class UDPClientSocket : public UDPSocket {
public:
UDPClientSocket ();
bool initializeClient (char * _peerAddr, int _peerPort);
};
~UDPClientSocket ( ); #endif // UDPCLIENTSOCKET_H
Server:
The server class encapsulates all the server operation. The constructor receives two parameters, which indicate the interface and the port that the server should listen on. The public method “serveRequest” should block upon calling it until a message is received from a client. The message type needs to be checked and verified that it is of type “Request” message. The method will use the three private methods “getRequest”, “doOperation”, and “sendReply” to execute the received request and send the results back to the client. All deserialization/unmarshalling and serialization/marshalling should take place inside “getRequest” and “sendReply” methods respectively. The “handleRequest” method acts as a dispatcher, which might need to instantiate more objects from different classes based on the message operation id to be able to perform the request tasks. For exercise 1, the logic of the echo server should be implemented inside the “doOperation” method without the need for the dispatcher. Prior to sending the reply, the message type should be set as a “Reply”.
#ifndef SERVER_H #define SERVER_H
class Server
{
private:
UDPServerSocket * udpServerSocket; Message * getRequest();
Message * doOperation();
public:void sendReply (Message * _message);
Server(char * _listen_hostname, int _listen_port); void serveRequest();
~server();
};
#endif // SERVER_H
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.