-
Notifications
You must be signed in to change notification settings - Fork 86
Expand file tree
/
Copy pathTest_WebSocket.cpp
More file actions
49 lines (36 loc) · 931 Bytes
/
Test_WebSocket.cpp
File metadata and controls
49 lines (36 loc) · 931 Bytes
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
#include "WebSocketConnect.h"
#include "WebSocketEvent.h"
#include "WebSocketPacket.h"
#include "WebSocketServer.h"
#include "EventLoop.h"
#include "Tools.h"
#include <stdio.h>
class IWebEvent : public WebSocketEvent
{
public:
virtual void onHandshake(WebSocketConnect * conn){
printf("ÎÕÊֳɹ¦\n");
};
virtual void onAccept(WebSocketConnect * conn){
};
virtual void onClose(WebSocketConnect * conn){
printf("close connect\n");
};
virtual void onMsg(WebSocketConnect * conn, WebSocketPacket * pack){
const char * p = pack->getBodyData();
char buff[1024] = {0};
strncpy(buff, p, pack->getBodySize());
std::string s = Tools::utf8ToGbk(buff);
printf("%s\n", s.c_str());
conn->sendMsg(pack);
};
};
int main()
{
EventLoop::Instance()->init();
IWebEvent wevent;
WebSocketServer server(EventLoop::Instance(), &wevent);
server.listen("127.0.0.1", 8080);
EventLoop::Instance()->run();
return 0;
}