GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — cpp-swoole/server.cpp at master · 137-rick/cpp-swoole

Expand file tree

/

server.cpp

Copy path
More file actions
More file actions

Latest commit

 

History

History
History
83 lines (63 loc) · 1.7 KB
/

server.cpp

Copy path

File metadata and controls

83 lines (63 loc) · 1.7 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
#include "Server.h"
#include <iostream>
using namespace std;
using namespace swoole;
class MyServer : public Server
{
public:
MyServer(string _host, int _port, int _mode = SW_MODE_PROCESS, int _type = SW_SOCK_TCP) :
Server(_host, _port, _mode, _type)
{
}
virtual void onStart();
virtual void onShutdown(){
}
virtual void onWorkerStart(int worker_id){
}
virtual void onWorkerStop(int worker_id){
}
virtual void onReceive(int fd, string &data);
virtual void onConnect(int fd);
virtual void onClose(int fd);
virtual void onPacket(string &data, ClientInfo &clientInfo){
}
};
void MyServer::onReceive(int fd, string &data)
{
cout << "fd=" << fd << "data" << data << endl;
int ret;
char resp_data[SW_BUFFER_SIZE];
int n = snprintf(resp_data, SW_BUFFER_SIZE, (char *) "Server: %*s\n", (int) data.length(), data.c_str());
ret = this->send(fd, resp_data, (uint32_t) n);
if (ret < 0)
{
printf("send to client fail. errno=%d\n", errno);
}
else
{
printf("send %d bytes to client success. data=%s\n", n, resp_data);
}
this->close(fd);
}
void MyServer::onConnect(int fd)
{
printf("PID=%d\tConnect fd=%d\n", getpid(), fd);
}
void MyServer::onClose(int fd)
{
printf("PID=%d\tClose fd=%d\n", getpid(), fd);
}
void MyServer::onStart()
{
printf("server is start\n");
}
int main(int argc, char **argv)
{
MyServer server("127.0.0.1", 9501);
server.listen("127.0.0.1", 9502, SW_SOCK_UDP);
server.listen("::1", 9503, SW_SOCK_TCP6);
server.listen("::1", 9504, SW_SOCK_UDP6);
server.setEvents(EVENT_onStart | EVENT_onReceive | EVENT_onClose);
server.start();
return 0;
}
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.