By: Uri Gold & Kadan Haba

By: Uri Gold & Kadan Haba

<p> LIS – SERVER CLIENT CODE Documentation</p><p>(Local Information Service) By: Uri Gold & Kadan Haba Supervisor: Lev Rechnik & Alexander Arlievsky</p><p>1 General...... 4 COMMUNICATION.H...... 5 READ_WRITE_IP.H...... 7 ROOM MAKE INQUIRY...... 8 PERSON MAKE INQUIRY...... 8 UTILS.H...... 9</p><p>2 General</p><p>The LIS client is the client edge of the LIS client-server application. It is a simple to use GUI Dialog based MFC application that enables a user to send Inquiries to the Server and to receive results. The application’s main window enables the user to perform the following actions: 1. Set the configurations for the LIS CLIENT i.e. set the server’s IP address. 2. Send an inquiry about a room. 3. Send an inquiry about a person. After setting the server address, it’s saved into a file (ip_number.cfg), and will be loaded as default the next time the application is executed. The client opens a communication socket to the server and sends the inquiry. The server finds the results for the inquiry send it back and terminate the communication. If a secondary search is made (i.e. a search on one of a few results given), a new communication is opened and it’s sent as a new inquiry of a secondary type as explained in the client use manual. If the communication is terminated in the middle, appropriate messages will be given to the user.</p><p>3 COMMUNICATION.H</p><p>#ifndef CCOMMUNICATIN_H_ #define CCOMMUNICATIN_H_</p><p>#define LIS_PORT 58772 #define HOST_NAME_LENGHT 100</p><p>#define NUM_OF_RETRIES 5 #define RETRY_SLEEP_TIME 2000 #define SERVICE_NAME "LIS_SERVER"</p><p>/////////////////////////////////////////////////////////////////////////////////// // his file includes 3 classes that together are the communication path in the lis project. // the LIS is ment to be used in the future through BLUETOOTH communication, // and in order to enable both TCP/IP work for the time being, and BLUETOOTH in the future, // we "wraped" the socketing, and comunication activities with these classes. // in the future, all that needs to be done, is to implement these classes based on the new // communication chanels, leaving of course the intrface as it is. ///////////////////////////////////////////////////////////////////////////////////</p><p>/////////////////////////////////////////////////////////////////////////////////// // Class : LisSocket // Class Members : SOCKET socket_; the socket that is used for all // coomunications // // Methods : // 1. int Send(char* buffer, unsigned int lenght);</p><p>4 // the method sends the data stored in "buffer" at length "length" // and returns the number of characters sent. // 2. int Receive(char* buffer, unsigned int lenght); // the method receivs the data stored into "buffer" at length "length" // and returns the number of characters received.] // 3. void SetSocket(SOCKET s); sets the socket. // /////////////////////////////////////////////////////////////////////////////////// class LisSocket { public: LisSocket(); virtual ~LisSocket();</p><p>BOOL Init(); void Close();</p><p> int Send(char* buffer, unsigned int lenght); int Receive(char* buffer, unsigned int lenght);</p><p> inline void SetSocket(SOCKET s) { closesocket(socket_); socket_ = s; }; protected: SOCKET socket_; };</p><p>/////////////////////////////////////////////////////////////////////////////////// // Class : CServerCommunication // // Methods : // 1. BOOL Create(); // The function initializes the socket and preformes both bind and listen. // it returns true on success and false on error. // 2. LisSocket* Accept_client(); // The function preformes accept, to a new LisSocket, and // returnes it if successful, else NULL. /////////////////////////////////////////////////////////////////////////////////// class CServerCommunication : public LisSocket { </p><p>//Dont Change this API. public: CServerCommunication(); ~CServerCommunication() {};</p><p>BOOL Create(); LisSocket* Accept_client(); }; ///////////////////////////////////////////////////////////////////////////////////</p><p>/////////////////////////////////////////////////////////////////////////////////// // Class : CClientCommunication // // Methods : // 1. BOOL ConnectLisServer( int NumRetries = NUM_OF_RETRIES, </p><p>5 // int SleepMiliSec = RETRY_SLEEP_TIME); // The function connects socket_ to the server, // and returns true if successful, false else. // 2. void Close(); // The function closes the socket. // 3. void SetSocket( SOCKET socket); sets the socket. /////////////////////////////////////////////////////////////////////////////////// class CClientCommunication : public LisSocket { private: SOCKET remote_socket_; public: CClientCommunication(); ~CClientCommunication() {};</p><p>BOOL ConnectLisServer( int NumRetries = NUM_OF_RETRIES, int SleepMiliSec = RETRY_SLEEP_TIME); void Close(); //void SetSocket( SOCKET socket) { socket_ = socket; };</p><p>}; ///////////////////////////////////////////////////////////////////////////////////</p><p>#endif</p><p>READ_WRITE_IP.H</p><p>#ifndef READ_WRITE_IP_H_ #define READ_WRITE_IP_H_</p><p>#define SIZE_OF_LINE 256 #define IP_FILE_NAME "ip_number2.cfg"</p><p>/////////////////////////////////////////////////////////////////////////////////// // The ip file format: // The file is a regular text file. // the one and only line in it is the line that contains the ip number. // note: 1. That line should be the first line. // 2. That line must start with the ip string (no space or tab or // anything else.) // 3. A "new line" or "end of file" must be placed in the end of the // ip string. ///////////////////////////////////////////////////////////////////////////////////</p><p>/////////////////////////////////////////////////////////////////////////////////// // Function : int read_ip_from_file(char* file_name, char* result_ip);</p><p>6 // Parameters : char * file name, *result_ip // // Returns : 1 on success // 0 on failure // Explanation : The function opens the given file_name file for reading, // reads the ip number in it, and checks if the ip is // valid. // Note, the result_ip should be a pointer to a string // at length of 16 bytes at least! the result ip // will be written to it. /////////////////////////////////////////////////////////////////////////////////// int read_ip_from_file(char* file_name, char* result_ip);</p><p>/////////////////////////////////////////////////////////////////////////////////// // Function : int write_ip_to_file(char* file_name, char* ip); // Parameters : char * file name, *_ip // // Returns : 1 on success // 0 on failure // Explanation : The function opens the given file_name file for writing, // and writes there the ip. /////////////////////////////////////////////////////////////////////////////////// int write_ip_to_file(char* file_name, char* ip);</p><p>/////////////////////////////////////////////////////////////////////////////////// //internal functions bool check_ip_number(char* ip_string); bool copy_ip(char* ip_string, char* target); /////////////////////////////////////////////////////////////////////////////////// #endif</p><p>ROOM MAKE INQUIRY</p><p>///////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // a function that takes all search feilds and creats a cstring to be sent to the server. // The format in which the inquiries will be sent: // The feilds will apear in this order, and will be separated by "%". // 1.a char indicating the inquiry type. // r=searching for a ROOM. // 2.Room number. // 3.Room name. // 4.Area code. // 5.Phone Number. /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////</p><p>7 int make_inquiry(CString& );</p><p>PERSON MAKE INQUIRY</p><p>///////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // a function that takes all search feilds and creats a cstring to be sent to the server. // The format in which the inquiries will be sent: // The feilds will apear in this order, and will be separated by "%". // 1.a char indicating the inquiry type. // p= searching for a PERSON // 2.First name. // 3.Middle name. // 4.Last name. // 5.email. // 6.Room number. // 7.Room name. // 8.Area code. // 9.Phone Number. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////// int make_inquiry(CString& );</p><p>8 UTILS.H</p><p>/* utils.h*/ #ifndef UTILS_H_ #define UTILS_H_</p><p>#include "stdafx.h" #include "Resource.h" #include "SHOW_ROOM.h" #include "SHOW_PERSON.h" #include "SEARCH_RESULTS.h"</p><p>#include "CCommunication.h"</p><p>// General Definitions #define MAX_INQ_LEN 2000 // the Maximum size for an inquiry. #define NUM_OF_CONNECT_TRIES 2 // the number of tries to connect to the lis server.</p><p>/////////////////////////////////////////////////////////////////////////////////// // Function: bool is_valid(CString& cs); // Returns true if there are no "%" or ":" in the string // else false. /////////////////////////////////////////////////////////////////////////////////// bool is_valid(CString& cs);</p><p>/////////////////////////////////////////////////////////////////////////////////// // Function: int check_and_add(CString& cs, CString& result, int flag=0); // Removes spaces of the right end, changes all string to LOWER CASE, // addes it to the result and returns 1 if there are no "%" or ":". // else returns 0. // flag can have the following values: // 0 default => no spaces at the end, no "%", and no ":", // 1 don't allow spaces // 2 check if email /////////////////////////////////////////////////////////////////////////////////// int check_and_add(CString& cs, CString& result, int flag=0);</p><p>9 /////////////////////////////////////////////////////////////////////////////////// // Function: bool is_email(CString & email); // Checks if it is a valid email address: <user_name>@<domain> /////////////////////////////////////////////////////////////////////////////////// bool is_email(CString & email);</p><p>/////////////////////////////////////////////////////////////////////////////////// // Function : CString get_next_and_remove(char c, CString& source) // Parameters : char c : the seperating char // CString source: the source string, that will // be changed // Returns : a CString object, with the first string on the // source CString, intil the char c. // Explanation : the function is similar to strtok, for winCE. gets the left // of the first appearance // of the char c in the source CString. the seperated // string will be removed from the source. /////////////////////////////////////////////////////////////////////////////////// CString get_next_and_remove(char c, CString& source);</p><p>/////////////////////////////////////////////////////////////////////////////////// // Function : void result_handler(CString cs); // Parameters : CString cs : a formated result acording // to the format: // // Explanation : after sending an inquiry to the server, the client get back // a "result" that is a CString in a specific format. // this Function sends the result to the appropriate // window, for display, or for // a secondary inquiry.the function prompts if an // error occurred or no resultes found. /////////////////////////////////////////////////////////////////////////////////// void result_handler(CString cs);</p><p>/////////////////////////////////////////////////////////////////////////////////// // Function : int lis_atoi(CString cs); // Parameters : CString cs : a CString to be translated to an // integer. // CString source: the source string, that will be // changed // Explanation : the function is similar to atoi, for winCE. /////////////////////////////////////////////////////////////////////////////////// int lis_atoi(CString cs);</p><p>10 /////////////////////////////////////////////////////////////////////////////////// // Function : int ushort2char(int length, // const unsigned short* source, char* target); // Parameters : int length: the length of the source array. // const unsigned short* source: the source array // char* target : an array // to get the casted data. // Returns : 0 if the length is invalid, // or pointers invalid , or 1 otherwise. // Explanation : the function converts an array of unsigned short to an // array of char. for converting the buffer returned // by CString on the WinCE version. /////////////////////////////////////////////////////////////////////////////////// int ushort2char(int length,const unsigned short* source, char* target);</p><p>/////////////////////////////////////////////////////////////////////////////////// // Function : int char2ushort(int length, const char* source, // unsigned short* target); // Parameters : int length: the length of the source array. // const unsigned short* source: the source array // char* target: an array to get the casted data. // Returns : 0 if the length is invalid, // or pointers invalid , or 1 otherwise. // Explanation : the function converts an array of char to an array of // unsigned short. to reverse ushort2char. /////////////////////////////////////////////////////////////////////////////////// int char2ushort(int length,const char* source, unsigned short* target);</p><p>/////////////////////////////////////////////////////////////////////////////////// // Function : int inquire(CString inq, CString& res); // Parameters : CString inq an inquiry to be sent. // : CString& res a CString in which the result will be put. // // Returns : the number of chares received, // or -1 on failure. // Explanation : the function tris to connect for // NUM_OF_CONNET_TRIES times, // and prompts for Retry / Cancel on failure. /////////////////////////////////////////////////////////////////////////////////// int inquire(CString inq, CString& res); </p><p>/////////////////////////////////////////////////////////////////////////////////// // Function : DWORD WINAPI Connection_Symbol(LPVOID p); // Explanation : the function will open a thread and run an animated // signal for the user to see that the program is running, // while waiting for the servers reply. /////////////////////////////////////////////////////////////////////////////////// DWORD WINAPI Connection_Symbol(LPVOID p);</p><p>11 /////////////////////////////////////////////////////////////////////////////////// // Function : void set_horiz_scrol(CListBox* pmyListBox); // Parameters : CListBox* pmyListBox: a CListBox in which we want // to activate the horizontal scrol bar. /////////////////////////////////////////////////////////////////////////////////// void set_horiz_scrol(CListBox* pmyListBox);</p><p>#endif</p><p>12</p>

View Full Text

Details

  • File Type
    pdf
  • Upload Time
    -
  • Content Languages
    English
  • Upload User
    Anonymous/Not logged-in
  • File Pages
    12 Page
  • File Size
    -

Download

Channel Download Status
Express Download Enable

Copyright

We respect the copyrights and intellectual property rights of all users. All uploaded documents are either original works of the uploader or authorized works of the rightful owners.

  • Not to be reproduced or distributed without explicit permission.
  • Not used for commercial purposes outside of approved use cases.
  • Not used to infringe on the rights of the original creators.
  • If you believe any content infringes your copyright, please contact us immediately.

Support

For help with questions, suggestions, or problems, please contact us