├── Projects
├── demo.e
├── epl.ws.dll
├── cpprest140_2_9.dll
├── WebSocket Library for EPL.e
└── WebSocket Library for EPL.ec
├── epl_ws
├── epl_ws
│ ├── stdafx.h
│ ├── epl_ws.cpp
│ ├── stdafx.cpp
│ ├── targetver.h
│ ├── apis.def
│ ├── packages.config
│ ├── epl_ws.vcxproj.filters
│ ├── SocksDominator.cpp
│ ├── SocksDominator.h
│ └── epl_ws.vcxproj
└── epl_ws.sln
├── readme.md
├── .gitignore
└── LICENSE
/Projects/demo.e:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kirino17/epl_ws/HEAD/Projects/demo.e
--------------------------------------------------------------------------------
/Projects/epl.ws.dll:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kirino17/epl_ws/HEAD/Projects/epl.ws.dll
--------------------------------------------------------------------------------
/epl_ws/epl_ws/stdafx.h:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kirino17/epl_ws/HEAD/epl_ws/epl_ws/stdafx.h
--------------------------------------------------------------------------------
/epl_ws/epl_ws/epl_ws.cpp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kirino17/epl_ws/HEAD/epl_ws/epl_ws/epl_ws.cpp
--------------------------------------------------------------------------------
/epl_ws/epl_ws/stdafx.cpp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kirino17/epl_ws/HEAD/epl_ws/epl_ws/stdafx.cpp
--------------------------------------------------------------------------------
/epl_ws/epl_ws/targetver.h:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kirino17/epl_ws/HEAD/epl_ws/epl_ws/targetver.h
--------------------------------------------------------------------------------
/Projects/cpprest140_2_9.dll:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kirino17/epl_ws/HEAD/Projects/cpprest140_2_9.dll
--------------------------------------------------------------------------------
/Projects/WebSocket Library for EPL.e:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kirino17/epl_ws/HEAD/Projects/WebSocket Library for EPL.e
--------------------------------------------------------------------------------
/Projects/WebSocket Library for EPL.ec:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kirino17/epl_ws/HEAD/Projects/WebSocket Library for EPL.ec
--------------------------------------------------------------------------------
/epl_ws/epl_ws/apis.def:
--------------------------------------------------------------------------------
1 | LIBRARY "epl.ws.dll"
2 |
3 | EXPORTS
4 | WSLinkStart
5 | WSDestory
6 | WSLinkReadyState
7 | WSLinkByteLength
8 | WSLinkCopyTextBuffer
9 | WSLinkCopyBinaryBuffer
10 | WSLinkCursor
11 | WSLinkSend
12 | WSLinkSendb
13 | WSLinkClose
14 |
--------------------------------------------------------------------------------
/readme.md:
--------------------------------------------------------------------------------
1 | epl_ws
2 | =================================
3 |
4 | 这是一个可以在"EPL"语言上使用的websocket库,它依据[cpprestsdk](https://archive.codeplex.com/?p=casablanca)进行创作编写而来; 得益于C++的`PPL`异步串行模式库的使用让`epl_ws`在逻辑层面上变得清晰且优雅。
5 |
6 | complie
7 | ---------------------------------
8 |
9 | 采用`Visual Studio 2015`编译本工具源代码。
10 |
11 | sample
12 | ---------------------------------
13 |
14 | 在`demo.e`代码中拥有详细的使用示范,需要参考时,可以打开看看它。
15 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # Prerequisites
2 | *.d
3 |
4 | # Compiled Object files
5 | *.slo
6 | *.lo
7 | *.o
8 | *.obj
9 |
10 | # Precompiled Headers
11 | *.gch
12 | *.pch
13 | *.pdb
14 |
15 | # Compiled Dynamic libraries
16 | *.so
17 | *.dylib
18 |
19 |
20 | # Fortran module files
21 | *.mod
22 | *.smod
23 |
24 | # Compiled Static libraries
25 | *.lai
26 | *.la
27 | *.a
28 | *.lib
29 |
30 | # Executables
31 | *.exe
32 | *.out
33 | *.app
34 |
35 | Projects/demo.bak
36 | epl_ws/.vs
37 | epl_ws/Debug
38 | epl_ws/epl_ws/Debug
39 | epl_ws/epl_ws/Release
40 | epl_ws/packages
41 |
--------------------------------------------------------------------------------
/epl_ws/epl_ws/packages.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2018 kirino17
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/epl_ws/epl_ws.sln:
--------------------------------------------------------------------------------
1 |
2 | Microsoft Visual Studio Solution File, Format Version 12.00
3 | # Visual Studio 15
4 | VisualStudioVersion = 15.0.27130.2027
5 | MinimumVisualStudioVersion = 10.0.40219.1
6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "epl_ws", "epl_ws\epl_ws.vcxproj", "{E1D11972-6CAA-4647-9140-D5BEF02BC475}"
7 | EndProject
8 | Global
9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
10 | Debug|x64 = Debug|x64
11 | Debug|x86 = Debug|x86
12 | Release|x64 = Release|x64
13 | Release|x86 = Release|x86
14 | EndGlobalSection
15 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
16 | {E1D11972-6CAA-4647-9140-D5BEF02BC475}.Debug|x64.ActiveCfg = Debug|x64
17 | {E1D11972-6CAA-4647-9140-D5BEF02BC475}.Debug|x64.Build.0 = Debug|x64
18 | {E1D11972-6CAA-4647-9140-D5BEF02BC475}.Debug|x86.ActiveCfg = Debug|Win32
19 | {E1D11972-6CAA-4647-9140-D5BEF02BC475}.Debug|x86.Build.0 = Debug|Win32
20 | {E1D11972-6CAA-4647-9140-D5BEF02BC475}.Release|x64.ActiveCfg = Release|x64
21 | {E1D11972-6CAA-4647-9140-D5BEF02BC475}.Release|x64.Build.0 = Release|x64
22 | {E1D11972-6CAA-4647-9140-D5BEF02BC475}.Release|x86.ActiveCfg = Release|Win32
23 | {E1D11972-6CAA-4647-9140-D5BEF02BC475}.Release|x86.Build.0 = Release|Win32
24 | EndGlobalSection
25 | GlobalSection(SolutionProperties) = preSolution
26 | HideSolutionNode = FALSE
27 | EndGlobalSection
28 | GlobalSection(ExtensibilityGlobals) = postSolution
29 | SolutionGuid = {4B47789A-89D6-4DD2-86FA-487BC4D90871}
30 | EndGlobalSection
31 | EndGlobal
32 |
--------------------------------------------------------------------------------
/epl_ws/epl_ws/epl_ws.vcxproj.filters:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF}
6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx
7 |
8 |
9 | {93995380-89BD-4b04-88EB-625FBE52EBFB}
10 | h;hh;hpp;hxx;hm;inl;inc;xsd
11 |
12 |
13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01}
14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms
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 |
--------------------------------------------------------------------------------
/epl_ws/epl_ws/SocksDominator.cpp:
--------------------------------------------------------------------------------
1 | #include "stdafx.h"
2 | #include "SocksDominator.h"
3 |
4 |
5 | SocksDominator::SocksDominator(const char *domain, LPFN_WS_EVENT_CALLBACK onopen,
6 | LPFN_WS_EVENT_CALLBACK onmessage,
7 | LPFN_WS_EVENT_CALLBACK onclose,
8 | LPFN_WS_EVENT_CALLBACK onerror)
9 | {
10 | m_domain = domain;
11 | m_onopen = onopen;
12 | m_onmessage = onmessage;
13 | m_onclose = onclose;
14 | m_onerror = onerror;
15 | m_readyState = 0;
16 | }
17 |
18 |
19 | SocksDominator::~SocksDominator()
20 | {
21 |
22 | }
23 |
24 | void SocksDominator::OnMsgDispatchs(void) {
25 | this->GetHandler()->receive().then([this](websocket_incoming_message body) ->void {
26 | if (body.message_type() == websocket_message_type::close) {
27 | if (this->GetCallback(WS_EVT_CLOSE)) {
28 | this->SetReadyState(WS_STATE_CLOSING);
29 | this->GetCallback(WS_EVT_CLOSE)((DWORD)this);
30 |
31 | this->GetHandler()->close().then([this]() ->void {
32 | this->SetReadyState(WS_STATE_CLOSE);
33 | }).then([this](pplx::task t) {
34 | try
35 | {
36 | t.get();
37 | }
38 | catch (const std::exception& ex)
39 | {
40 | this->SetReadyState(WS_STATE_CLOSE);
41 | }
42 | });
43 | }
44 | return;
45 | }
46 | this->SetBody(&body);
47 | if (this->GetCallback(WS_EVT_ONMESSAGE)) {
48 | this->GetCallback(WS_EVT_ONMESSAGE)((DWORD)this);
49 | this->OnMsgDispatchs();
50 | }
51 | }).then([this](pplx::task t) ->void {
52 | try
53 | {
54 | t.get();
55 | }
56 | catch (const std::exception& ex)
57 | {
58 | if (this->GetCallback(WS_EVT_CLOSE)) {
59 | this->SetReadyState(WS_STATE_CLOSE);
60 | this->GetCallback(WS_EVT_CLOSE)((DWORD)this);
61 | }
62 | }
63 | });
64 | }
--------------------------------------------------------------------------------
/epl_ws/epl_ws/SocksDominator.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 | #include
3 | #include
4 | #include
5 | #include
6 | #include
7 | #include
8 | #include "cpprest\containerstream.h"
9 | #include "cpprest\filestream.h"
10 | #include "cpprest\http_client.h"
11 | #include "cpprest\json.h"
12 | #include "cpprest\producerconsumerstream.h"
13 | #include "cpprest\details\web_utilities.h"
14 | #include "cpprest\uri.h"
15 | #include "cpprest\streams.h"
16 | #include "cpprest\ws_client.h"
17 | #include "cpprest\ws_msg.h"
18 | #include "cpprest\asyncrt_utils.h"
19 | #include
20 | #include
21 |
22 | using namespace pplx;
23 | using namespace utility;
24 | using namespace web;
25 | using namespace concurrency::streams;
26 | using namespace web::http;
27 | using namespace web::http::client;
28 | using namespace web::json;
29 | using namespace web::websockets::client;
30 |
31 |
32 | typedef void(CALLBACK *LPFN_WS_EVENT_CALLBACK)(DWORD e);
33 | #define WS_EVT_ONOPEN 0
34 | #define WS_EVT_ONMESSAGE 1
35 | #define WS_EVT_CLOSE 2
36 | #define WS_EVT_ERROR 3
37 |
38 | #define WS_STATE_CONNECTING 0
39 | #define WS_STATE_OPEN 1
40 | #define WS_STATE_CLOSING 2
41 | #define WS_STATE_CLOSE 3
42 |
43 | class SocksDominator
44 | {
45 | public:
46 | SocksDominator(const char *domain, LPFN_WS_EVENT_CALLBACK onopen,
47 | LPFN_WS_EVENT_CALLBACK onmessage,
48 | LPFN_WS_EVENT_CALLBACK onclose,
49 | LPFN_WS_EVENT_CALLBACK onerror);
50 | ~SocksDominator();
51 |
52 | websocket_client *GetHandler(void) { return &ws; }
53 |
54 | LPFN_WS_EVENT_CALLBACK GetCallback(int evt) {
55 | switch (evt)
56 | {
57 | case 0:
58 | return m_onopen;
59 | case 1:
60 | return m_onmessage;
61 | case 2:
62 | return m_onclose;
63 | case 3:
64 | return m_onerror;
65 | default:
66 | break;
67 | }
68 | return 0;
69 | }
70 |
71 | void SetBody(websocket_incoming_message *body) { m_body = body; }
72 |
73 | websocket_incoming_message *GetBody(void) { return m_body; };
74 |
75 | void Close(void) {
76 | this->SetReadyState(WS_STATE_CLOSING);
77 | this->GetHandler()->close().then([this]() {
78 | this->SetReadyState(WS_STATE_CLOSE);
79 | });
80 | }
81 |
82 | void SetReadyState(int state) {
83 | m_readyState = state;
84 | }
85 |
86 | int GetReadyState(void) { return m_readyState; }
87 |
88 | void OnMsgDispatchs(void);
89 |
90 | private:
91 | websocket_client ws;
92 | std::string m_domain;
93 | LPFN_WS_EVENT_CALLBACK m_onopen;
94 | LPFN_WS_EVENT_CALLBACK m_onmessage;
95 | LPFN_WS_EVENT_CALLBACK m_onclose;
96 | LPFN_WS_EVENT_CALLBACK m_onerror;
97 | websocket_incoming_message *m_body;
98 | int m_readyState;
99 | };
100 |
101 |
--------------------------------------------------------------------------------
/epl_ws/epl_ws/epl_ws.vcxproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Debug
6 | Win32
7 |
8 |
9 | Release
10 | Win32
11 |
12 |
13 | Debug
14 | x64
15 |
16 |
17 | Release
18 | x64
19 |
20 |
21 |
22 | 15.0
23 | {E1D11972-6CAA-4647-9140-D5BEF02BC475}
24 | Win32Proj
25 | eplws
26 | 10.0.16299.0
27 |
28 |
29 |
30 | Application
31 | true
32 | v140
33 | Unicode
34 |
35 |
36 | DynamicLibrary
37 | false
38 | v140
39 | true
40 | Unicode
41 | Static
42 |
43 |
44 | Application
45 | true
46 | v141
47 | Unicode
48 |
49 |
50 | Application
51 | false
52 | v141
53 | true
54 | Unicode
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 | true
76 |
77 |
78 | true
79 |
80 |
81 | false
82 | epl.ws
83 | .dll
84 | ..\..\Projects
85 |
86 |
87 | false
88 |
89 |
90 |
91 | Use
92 | Level3
93 | Disabled
94 | true
95 | WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)
96 | true
97 |
98 |
99 | Console
100 | true
101 | apis.def
102 |
103 |
104 |
105 |
106 | Use
107 | Level3
108 | Disabled
109 | true
110 | _DEBUG;_CONSOLE;%(PreprocessorDefinitions)
111 | true
112 |
113 |
114 | Console
115 | true
116 | apis.def
117 |
118 |
119 |
120 |
121 | Use
122 | Level3
123 | MaxSpeed
124 | true
125 | true
126 | true
127 | WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)
128 | true
129 |
130 |
131 | Windows
132 | true
133 | true
134 | true
135 | apis.def
136 |
137 |
138 |
139 |
140 | Use
141 | Level3
142 | MaxSpeed
143 | true
144 | true
145 | true
146 | NDEBUG;_CONSOLE;%(PreprocessorDefinitions)
147 | true
148 |
149 |
150 | Console
151 | true
152 | true
153 | true
154 | apis.def
155 |
156 |
157 |
158 |
159 |
160 |
161 |
162 |
163 |
164 |
165 |
166 | Create
167 | Create
168 | Create
169 | Create
170 |
171 |
172 |
173 |
174 |
175 |
176 |
177 |
178 |
179 |
180 |
181 |
182 |
183 |
184 |
185 |
186 |
187 |
188 | 这台计算机上缺少此项目引用的 NuGet 程序包。使用“NuGet 程序包还原”可下载这些程序包。有关更多信息,请参见 http://go.microsoft.com/fwlink/?LinkID=322105。缺少的文件是 {0}。
189 |
190 |
191 |
192 |
193 |
194 |
195 |
196 |
197 |
198 |
--------------------------------------------------------------------------------