Compare commits
No commits in common. "b6f13379adb0196cc9fbd6e4b84974401b47fbcb" and "dbde770e4fce60145f03cb7d862f8136ee5a52e4" have entirely different histories.
b6f13379ad
...
dbde770e4f
5
.vscode/extensions.json
vendored
5
.vscode/extensions.json
vendored
@ -1,5 +0,0 @@
|
|||||||
{
|
|
||||||
"recommendations": [
|
|
||||||
"ms-vscode.cmake-tools"
|
|
||||||
]
|
|
||||||
}
|
|
25044
testjson/json.hpp
25044
testjson/json.hpp
File diff suppressed because it is too large
Load Diff
Binary file not shown.
@ -1,91 +0,0 @@
|
|||||||
#include "json.hpp"
|
|
||||||
using json = nlohmann::json;
|
|
||||||
|
|
||||||
#include <iostream>
|
|
||||||
#include <vector>
|
|
||||||
#include <map>
|
|
||||||
#include <string>
|
|
||||||
using namespace std;
|
|
||||||
|
|
||||||
string fun1(){
|
|
||||||
json js;
|
|
||||||
js["msg_type"] = 2;
|
|
||||||
js["from"] = "zhangsan";
|
|
||||||
js["to"] = "lisi";
|
|
||||||
js["msg"] = "hello";
|
|
||||||
|
|
||||||
cout << js << endl;
|
|
||||||
string sendjs = js.dump();
|
|
||||||
cout << sendjs.c_str() << endl;
|
|
||||||
|
|
||||||
return sendjs;
|
|
||||||
}
|
|
||||||
|
|
||||||
string fun2(){
|
|
||||||
json js2;
|
|
||||||
js2["msg_id"] = {1,2,3,4,5};
|
|
||||||
js2["msg"]["msg_a"] = "a";
|
|
||||||
js2["msg"]["msg_b"] = "b";
|
|
||||||
js2["msg"] = {{"msg_aa","aa"},{"msg_bb","bb"}};
|
|
||||||
|
|
||||||
cout << js2 <<endl;
|
|
||||||
string sendjs2 = js2.dump();
|
|
||||||
cout << sendjs2.c_str() << endl;
|
|
||||||
return sendjs2;
|
|
||||||
}
|
|
||||||
|
|
||||||
string fun3(){
|
|
||||||
vector<int> v;
|
|
||||||
v.push_back(1);
|
|
||||||
v.push_back(2);
|
|
||||||
v.push_back(3);
|
|
||||||
|
|
||||||
json js3;
|
|
||||||
js3["j_vec"] = v;
|
|
||||||
|
|
||||||
map<int,string> m;
|
|
||||||
m[1] = "m1";
|
|
||||||
m[2] = "m2";
|
|
||||||
m.insert({3,"m3"});
|
|
||||||
|
|
||||||
js3["j_map"] = m;
|
|
||||||
|
|
||||||
cout << js3 << endl;
|
|
||||||
string sendjs3 = js3.dump();
|
|
||||||
cout << sendjs3.c_str() << endl;
|
|
||||||
|
|
||||||
return sendjs3;
|
|
||||||
}
|
|
||||||
|
|
||||||
int main(){
|
|
||||||
//fun1();
|
|
||||||
//fun2();
|
|
||||||
//fun3();
|
|
||||||
|
|
||||||
string recvjs = fun1();
|
|
||||||
json js = json::parse(recvjs);
|
|
||||||
cout << js <<endl;
|
|
||||||
|
|
||||||
string recvjs2 = fun2();
|
|
||||||
json js2 = json::parse(recvjs2);
|
|
||||||
cout << js2["msg_id"] <<endl;
|
|
||||||
auto arr = js2["msg_id"];
|
|
||||||
cout << arr[2] << endl;
|
|
||||||
|
|
||||||
string arcvjs3 = fun3();
|
|
||||||
json js3 = json::parse(arcvjs3);
|
|
||||||
vector<int> v = js3["j_vec"];
|
|
||||||
map<int,string> m = js3["j_map"];
|
|
||||||
for(int i : v){
|
|
||||||
cout << i;
|
|
||||||
}
|
|
||||||
cout << endl;
|
|
||||||
for(auto j : m){
|
|
||||||
cout << j.first <<" " << j.second << endl;
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -1,39 +0,0 @@
|
|||||||
|
|
||||||
/*
|
|
||||||
muduo网络库给用户提供了两个主要的类
|
|
||||||
TcpServer :用于编写服务器程序的
|
|
||||||
TcpClient :用于编写客户端程序的
|
|
||||||
|
|
||||||
epoll+线程池
|
|
||||||
好处 :能够把网络I/O的代码和业务代码区分开
|
|
||||||
用户的连接和断开 用户的可读写事件
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include <muduo/net/TcpServer.h>
|
|
||||||
#include <muduo/net/EventLoop.h>
|
|
||||||
#include <iostream>
|
|
||||||
using namespace std;
|
|
||||||
using namespace muduo;
|
|
||||||
using namespace muduo::net;
|
|
||||||
|
|
||||||
class ChatServer{
|
|
||||||
public:
|
|
||||||
ChatServer(EventLoop* loop,
|
|
||||||
const InetAddress& listenAddr,
|
|
||||||
const string& nameArg)
|
|
||||||
:_server(loop,listenAddr,nameArg),_loop(loop)
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
|
||||||
TcpServer _server;
|
|
||||||
EventLoop* _loop;
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user