-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.cpp
More file actions
80 lines (74 loc) · 2.01 KB
/
server.cpp
File metadata and controls
80 lines (74 loc) · 2.01 KB
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
#include "sock_wrap.h"
#include "dbms.hpp"
#include "interpret.hpp"
#include <fstream>
using namespace ModelSQL;
class MyServerSocket : public ServerSocket
{
public:
MyServerSocket() : ServerSocket(default_address) {}
void OnAccept(BaseSocket *pConn)
{
// sending the request for the file name
pConn->PutString(server_invitation);
std::string str;
std::string f_name;
f_name = pConn->GetString();
f_name.pop_back();
pConn->PutString(server_stop);
while ((str = pConn->GetString()) != "END\n")
{
//change standard output for .h-files working
std::ofstream out(f_name);
std::streambuf *coutbuf = std::cout.rdbuf();
std::cout.rdbuf(out.rdbuf());
try
{
std::cerr << "'" << str << "'" << std::endl;
Interpreter obj(str);
pConn->PutString("OK"); // get an answer
}
catch (SocketException &e)
{
// error --- input to the screen
e.report();
pConn->PutString (e.Message);
}
catch (SQL_Xception &e)
{
// error --- input to the screen
e.report();
pConn->PutString (e.Message);
}
catch (Xception &e)
{
// error --- input to the screen
e.report();
pConn->PutString (e.Message);
}
catch (...)
{
std::cerr << "OnAccept: unknown error" << std::endl;
}
std::cout.rdbuf(coutbuf);
}
pConn->PutString("END");
delete pConn;
remove (default_address);
// delete mysocket
}
};
int main()
{
try
{
MyServerSocket sock;
sock.OnAccept(sock.Accept());
}
catch (SocketException &e)
{
// error --- input to the screen
e.report();
}
return 0;
}