- •Contents of the Report
- •Introduction
- •1. Algorithm of the service program
- •2. Algorithms of the service management program
- •3. Algorithm of the client program
- •4. Implementation of service program
- •5. Implementation of service management program
- •6. Implementation of client program
- •Appendix a Source code of service program
- •Appendix b Source code of scm_console program
- •Appendix c Source code of client program
Appendix c Source code of client program
AD. 091501.06/67833.
Pages______
Donetsk - 2010
#include "stdafx.h"
#include <stdio.h>
#include <conio.h>
#include <iostream>
#include <windows.h>
#define PIPE_ERROR 1;
#ifdef UNICODE
#define tcin wcin
#define tcout wcout
#else
#define tcin cin
#define tcout cout
#endif
#define BUFSIZE 16
using namespace std;
SYSTEMTIME systime;
HANDLE hPipe;
LPTSTR lPipename = _T("\\\\.\\pipe\\mypipe");
TCHAR chBuf[512];
//function opening pipe handler
INT open_pipe(VOID)
{
BOOL bSuccess = FALSE;
DWORD dwPipeMode;
hPipe = CreateFile(lPipename,GENERIC_READ|GENERIC_WRITE,0,NULL,OPEN_EXISTING,0,NULL);
if (hPipe == INVALID_HANDLE_VALUE)
{
tcout<<"CreateFile Error. no pipe exists"<<endl;
return PIPE_ERROR;
}
dwPipeMode = PIPE_READMODE_MESSAGE;
bSuccess = SetNamedPipeHandleState(hPipe,&dwPipeMode,NULL,NULL);
if (!bSuccess)
{
tcout<<"SetNamedPipeHandleState Error"<<endl;
return PIPE_ERROR;
}
return 0;//all succesfull done
}
VOID close_pipe(VOID)
{
CloseHandle(hPipe);
hPipe = INVALID_HANDLE_VALUE;
}
VOID menu(VOID)
{
tcout<<"\n\tVasin Dmitriy Evgenievich. KC-07g. Variant #2”<<endl;
tcout<<"1. Receive the command line."<<endl;
tcout<<"2. Exit."<<endl;
}
VOID date_time(VOID)
{
SHORT i = 0;
DWORD cbRead = 0, cbWrit = 0;
BOOL cond = FALSE;
BOOL bSuccess = FALSE;
//write pipe
TCHAR toService[512]="REQUEST";
bSuccess = WriteFile(hPipe,toService,strlen(toService),&cbWrit,NULL);
FlushFileBuffers(hPipe);
if (bSuccess) tcout<<"The string of request has been sent"<<endl;
else tcout<<"The string of request has not been sent !!!"<<endl;
bSuccess = ReadFile(hPipe,chBuf,512,&cbRead,NULL);
if (cbRead!=0)
{
int i=0;
while (i<100)
{
cout<<chBuf[i];
i++;
}
}
else
{
cout<<"!!! The answer from service was not successful !!!";
//cout<<"VIVOD !!!"<<endl;
int i=0;
while (i<100)
{
cout<<chBuf[i];
i++;
}
}
}
int _tmain(int argc, _TCHAR* argv[])
{
BOOL cond = TRUE;
CHAR ch;
while (cond)
{
menu();
ch=getch();
switch (ch)
{
case '1':
if (!open_pipe())
{
date_time();
close_pipe();
}
break;
case '2':
tcout<<"\aGoodbye."<<endl;
getch();
cond = false;
break;
}
}
close_pipe();
getch();
return 0;
}