-
Notifications
You must be signed in to change notification settings - Fork 0
/
simple_client_main.cpp
189 lines (147 loc) · 3.88 KB
/
simple_client_main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
#include <stdio.h>
#include <cstdlib>
#include <unistd.h>
#include "ClientSocket.h"
#include "SocketException.h"
#include <string.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/signal.h>
#include <sys/wait.h>
#include <sys/resource.h>
#include <netinet/in.h>
#include <netdb.h>
#include <arpa/inet.h>
#include <locale.h>
#include <iostream>
#include <sstream>
using namespace std;
void clrscr(void);
int MainMenu();
void AddTicket(string ,ClientSocket);
void OutputTickets(string ,ClientSocket );
enum Menu
{
t_AddTicket=1,
t_OutputTickets,
t_DeleteTicket,
t_SortTickets,
t_SearchTicket,
t_Exit
};
struct Ticket
{
string film_name;
double film_price;
string film_time;
};
int main ( int argc, char **argv )
{
try
{
ClientSocket client_socket ( "localhost", 7500 );
try //посылка запроса ,полученеи овтета и т.д.
{
/*client_socket << "Test message.";
client_socket >> reply;*/
while(true)
{
string buffer;
switch (MainMenu())
{
case t_AddTicket: clrscr();cout<<"fdfdfdf";AddTicket(buffer,client_socket);clrscr();break;
//case t_OutputTickets:clrscr();OutputTickets(buffer,client_socket);clrscr();break;
case t_DeleteTicket: break;
case t_SortTickets: break;
case t_SearchTicket: break;
case t_Exit: exit(0);
}
}
}
catch ( SocketException& ) {}
}
catch ( SocketException& e )
{
std::cout << "Exception was caught:" << e.description() << "\n";
}
return 0;
}
void clrscr(void)
{
char a[80];
printf("\033[2J"); /* Clear the entire screen. */
printf("\033[0;0f"); /* Move cursor to the top left hand corner
*/
}
int MainMenu()
{
clrscr();
cout<< "Добро пожаловать в программу!!!"<<endl;
cout<<"<1> Добавить билет"<<endl;
cout<<"<2> Просмотр существующих билетов"<<endl;
cout<<"<3> Удалить билет"<<endl;
cout<<"<4> Сортировка"<<endl;
cout<<"<5> Поиск"<<endl;
cout<<"<6> Выход"<<endl;
int chose;
while(!(cin>>chose)||chose<1||chose>6)
{
cin.clear();
while(cin.get()!='\n')
{
cout<<"Ошибка!!!Повторите ввод!!!"<<endl;
continue;
}
}
cin.ignore();
return chose;
}
void AddTicket(string buffer,ClientSocket client_socket)
{
buffer= "1";
client_socket<<buffer;
clrscr();
Ticket m;
cout << " ***Введите информацию о билете***" << endl;
cout << "Название фильм: ";
getline(cin, m.film_name);
client_socket<<m.film_name;
cout << "Стоимость билета($): ";
while (!(cin >>m.film_price) || m.film_price< 0) {
cin.clear();
while (cin.get() != '\n'){
continue;
cout << "Ошибка!!!Повторите ввод" << endl;
}
}
cin.ignore();
stringstream k;
k>>m.film_price;
k<<buffer;
client_socket<<buffer;
cout << "Время начала сеанса: ";
getline(cin, m.film_time);
client_socket<<m.film_time;
cout<<"ghhshsg"<<endl;
}
/*void OutputTickets(string ,ClientSocket)
{
buffer[0] ='2';
send(sock, buffer, 1, 0);
clrscr();
Ticket *p;
while (true)
{
recv(sock,buffer,sizeof(Ticket),0);
if (buffer[0] == '1')
break;
p = (Ticket *)buffer;
cout << "Название: " << p->film_name<< endl;
cout << "Стоимость билета: " << p->film_price << endl;
cout << "Время начала сеанса: " << p->film_time << endl;
cout << endl << endl;
}
sleep(4000);
//_getch();
}
* */