-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathecho_server.cpp
65 lines (54 loc) · 1.39 KB
/
echo_server.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
// echo_server.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#ifdef _MSC_VER
#pragma warning(disable: 4251) // needs to have dll-interface
#pragma warning(disable: 4267) // conversion from 'size_t' to 'long', possible loss of data
#pragma warning(disable: 4244) // conversion from '__w64 const unsigned int' to 'unsigned int', possible loss of data
#pragma comment(lib, "Ws2_32.lib")
#endif
#include <stdio.h>
#include <nark/rpc/server.hpp>
#include <nark/inet/SocketStream.hpp>
#include <iostream>
using namespace std;
using namespace nark;
using namespace nark::rpc;
#include "../echo.h"
rpc_ret_t Echo::echo(const std::string& msg, std::string* y)
{
cout << "input: " << msg << endl;
*y = "server: " + msg;
return 0;
}
int main0(int argc, char* argv[])
{
try {
SocketAcceptor acceptor("0.0.0.0:8001");
rpc_server<PortableDataInput, PortableDataOutput> server(&acceptor);
// ¼ÓÈëÃüÃûµÄ Servant
server.add_servant(
new Echo,
"echo",
0 // 0 will not auto create GlobaleScope Object
);
server.start();
}
catch (const std::exception& exp)
{
printf("exception: what=%s\n", exp.what());
}
return 0;
}
int main(int argc, char* argv[])
{
#if defined(_WIN32) || defined(_WIN64)
WSADATA information;
WSAStartup(MAKEWORD(2, 2), &information);
int ret = main0(argc, argv);
WSACleanup();
return ret;
#else
return main0(argc, argv);
#endif
}