Compare commits
	
		
			9 Commits
		
	
	
		
			v4.0.0
			...
			feature/vc
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
|  | 1af96ed4e4 | ||
|  | 7cb5cc05e4 | ||
|  | 750a752ac0 | ||
|  | 61e5f52286 | ||
|  | ce0b716f54 | ||
|  | aae8e5ec65 | ||
|  | 2723e8466e | ||
|  | f13c610352 | ||
|  | 55c65b08bf | 
							
								
								
									
										60
									
								
								.travis.yml
									
									
									
									
									
								
							
							
						
						
									
										60
									
								
								.travis.yml
									
									
									
									
									
								
							| @@ -12,23 +12,23 @@ matrix: | |||||||
|         - python test/run.py |         - python test/run.py | ||||||
|         - make ws |         - make ws | ||||||
|  |  | ||||||
|     # # Linux |     # Linux | ||||||
|     # - os: linux |  | ||||||
|     #   dist: xenial |  | ||||||
|     #   script:  |  | ||||||
|     #     - python test/run.py |  | ||||||
|     #     - make ws |  | ||||||
|     #   env: |  | ||||||
|     #     - CC=gcc |  | ||||||
|     #     - CXX=g++ |  | ||||||
|  |  | ||||||
|     # Clang + Linux disabled for now |  | ||||||
|     - os: linux |     - os: linux | ||||||
|       dist: xenial |       dist: xenial | ||||||
|       script: python test/run.py |       script:  | ||||||
|  |         - python test/run.py | ||||||
|  |         - make ws | ||||||
|       env: |       env: | ||||||
|         - CC=clang  |         - CC=gcc | ||||||
|         - CXX=clang++ |         - CXX=g++ | ||||||
|  |  | ||||||
|  |     # Clang + Linux disabled for now | ||||||
|  |     # - os: linux | ||||||
|  |     #   dist: xenial | ||||||
|  |     #   script: python test/run.py | ||||||
|  |     #   env: | ||||||
|  |     #     - CC=clang  | ||||||
|  |     #     - CXX=clang++ | ||||||
|  |  | ||||||
|     # Windows |     # Windows | ||||||
|     - os: windows |     - os: windows | ||||||
| @@ -36,6 +36,36 @@ matrix: | |||||||
|         - CMAKE_PATH="/c/Program Files/CMake/bin" |         - CMAKE_PATH="/c/Program Files/CMake/bin" | ||||||
|       script:  |       script:  | ||||||
|         - export PATH=$CMAKE_PATH:$PATH |         - export PATH=$CMAKE_PATH:$PATH | ||||||
|         - cmake -DUSE_TLS=1 -DUSE_WS=1 -DUSE_MBED_TLS=1 . |         - cmake -DUSE_TLS=1 -DUSE_WS=1 -DUSE_MBED_TLS=1 -DUSE_VENDORED_THIRD_PARTY=1 . | ||||||
|         - cmake --build --parallel . |         - cmake --build --parallel . | ||||||
|         - python test/run.py |         - python test/run.py | ||||||
|  |  | ||||||
|  | install: | ||||||
|  |   # HACK: gcc 8.0.1 is missing movdirintrin.h so just download it. We need this for GLM and Vectrexy to build. | ||||||
|  |   - sudo wget https://raw.githubusercontent.com/gcc-mirror/gcc/gcc-8-branch/gcc/config/i386/movdirintrin.h -P /usr/lib/gcc/x86_64-linux-gnu/8/include/ | ||||||
|  |  | ||||||
|  |   # Create deps dir | ||||||
|  |   - mkdir -p ${DEPS_DIR} | ||||||
|  |  | ||||||
|  |   # Set compiler vars | ||||||
|  |   - export CC=${CC_COMPILER} | ||||||
|  |   - export CXX=${CXX_COMPILER} | ||||||
|  |  | ||||||
|  |   # Install vcpkg and dependencies | ||||||
|  |   - | | ||||||
|  |     set -e | ||||||
|  |     mkdir -p ${DEPS_DIR}/vcpkg | ||||||
|  |     pushd ${DEPS_DIR}/vcpkg | ||||||
|  |     git init | ||||||
|  |     git remote add origin https://github.com/Microsoft/vcpkg.git | ||||||
|  |     git fetch origin master | ||||||
|  |     git checkout -b master origin/master | ||||||
|  |     ./bootstrap-vcpkg.sh | ||||||
|  |     # Only build release libs to save time. We inject a new line first since some cmake files don't end with one. | ||||||
|  |     echo -e '\nset(VCPKG_BUILD_TYPE release)' >> ./triplets/${VCPKG_TRIPLET}.cmake | ||||||
|  |     ./vcpkg install sdl2 sdl2-net glew glm stb imgui | ||||||
|  |     popd | ||||||
|  |  | ||||||
|  | cache: | ||||||
|  |   directories: | ||||||
|  | - ${DEPS_DIR}/vcpkg/installed | ||||||
|   | |||||||
| @@ -1,13 +1,18 @@ | |||||||
| # Changelog | # Changelog | ||||||
| All notable changes to this project will be documented in this file. | All notable changes to this project will be documented in this file. | ||||||
|  |  | ||||||
|  | ## [unreleased] - 2019-06-09 | ||||||
|  | ### Changed | ||||||
|  | - mbedtls and zlib are searched with find_package, and we use the vendored version if nothing is found | ||||||
|  | - travis CI uses g++ on Linux | ||||||
|  |  | ||||||
| ## [4.0.0] - 2019-06-09 | ## [4.0.0] - 2019-06-09 | ||||||
| ### Changed | ### Changed | ||||||
| - WebSocket::send() sends message in TEXT mode by default | - WebSocket::send() sends message in TEXT mode by default | ||||||
| - WebSocketMessage sets a new binary field, which tells whether the received incoming message is binary or text | - WebSocketMessage sets a new binary field, which tells whether the received incoming message is binary or text | ||||||
| - WebSocket::send takes a third arg, binary which default to true (can be text too) | - WebSocket::send takes a third arg, binary which default to true (can be text too) | ||||||
| - WebSocket callback only take one object, a const ix::WebSocketMessagePtr& msg | - WebSocket callback only take one object, a const ix::WebSocketMessagePtr& msg | ||||||
| - Add explicite WebSocket::sendBinary | - Add explicit WebSocket::sendBinary method | ||||||
| - New headers + WebSocketMessage class to hold message data, still not used across the board | - New headers + WebSocketMessage class to hold message data, still not used across the board | ||||||
| - Add test/compatibility folder with small servers and clients written in different languages and different libraries to test compatibility. | - Add test/compatibility folder with small servers and clients written in different languages and different libraries to test compatibility. | ||||||
| - ws echo_server has a -g option to print a greeting message on connect | - ws echo_server has a -g option to print a greeting message on connect | ||||||
|   | |||||||
							
								
								
									
										13
									
								
								CMake/FindMbedTLS.cmake
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										13
									
								
								CMake/FindMbedTLS.cmake
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,13 @@ | |||||||
|  | find_path(MBEDTLS_INCLUDE_DIRS mbedtls/ssl.h) | ||||||
|  |  | ||||||
|  | find_library(MBEDTLS_LIBRARY mbedtls) | ||||||
|  | find_library(MBEDX509_LIBRARY mbedx509) | ||||||
|  | find_library(MBEDCRYPTO_LIBRARY mbedcrypto) | ||||||
|  |  | ||||||
|  | set(MBEDTLS_LIBRARIES "${MBEDTLS_LIBRARY}" "${MBEDX509_LIBRARY}" "${MBEDCRYPTO_LIBRARY}") | ||||||
|  |  | ||||||
|  | include(FindPackageHandleStandardArgs) | ||||||
|  | find_package_handle_standard_args(MBEDTLS DEFAULT_MSG | ||||||
|  |     MBEDTLS_INCLUDE_DIRS MBEDTLS_LIBRARY MBEDX509_LIBRARY MBEDCRYPTO_LIBRARY) | ||||||
|  |  | ||||||
|  | mark_as_advanced(MBEDTLS_INCLUDE_DIRS MBEDTLS_LIBRARY MBEDX509_LIBRARY MBEDCRYPTO_LIBRARY) | ||||||
| @@ -4,6 +4,8 @@ | |||||||
| # | # | ||||||
|  |  | ||||||
| cmake_minimum_required(VERSION 3.4.1) | cmake_minimum_required(VERSION 3.4.1) | ||||||
|  | set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/CMake;${CMAKE_MODULE_PATH}") | ||||||
|  |  | ||||||
| project(ixwebsocket C CXX) | project(ixwebsocket C CXX) | ||||||
|  |  | ||||||
| set (CMAKE_CXX_STANDARD 14) | set (CMAKE_CXX_STANDARD 14) | ||||||
| @@ -20,64 +22,64 @@ if ("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang") | |||||||
| endif() | endif() | ||||||
|  |  | ||||||
| set( IXWEBSOCKET_SOURCES | set( IXWEBSOCKET_SOURCES | ||||||
|  |     ixwebsocket/IXCancellationRequest.cpp | ||||||
|  |     ixwebsocket/IXConnectionState.cpp | ||||||
|  |     ixwebsocket/IXDNSLookup.cpp | ||||||
|  |     ixwebsocket/IXHttpClient.cpp | ||||||
|  |     ixwebsocket/IXNetSystem.cpp | ||||||
|  |     ixwebsocket/IXSelectInterrupt.cpp | ||||||
|  |     ixwebsocket/IXSelectInterruptFactory.cpp | ||||||
|     ixwebsocket/IXSocket.cpp |     ixwebsocket/IXSocket.cpp | ||||||
|     ixwebsocket/IXSocketServer.cpp |  | ||||||
|     ixwebsocket/IXSocketConnect.cpp |     ixwebsocket/IXSocketConnect.cpp | ||||||
|     ixwebsocket/IXSocketFactory.cpp |     ixwebsocket/IXSocketFactory.cpp | ||||||
|     ixwebsocket/IXDNSLookup.cpp |     ixwebsocket/IXSocketServer.cpp | ||||||
|     ixwebsocket/IXCancellationRequest.cpp |     ixwebsocket/IXUrlParser.cpp | ||||||
|     ixwebsocket/IXNetSystem.cpp |  | ||||||
|     ixwebsocket/IXWebSocket.cpp |     ixwebsocket/IXWebSocket.cpp | ||||||
|     ixwebsocket/IXWebSocketServer.cpp |     ixwebsocket/IXWebSocketCloseConstants.cpp | ||||||
|     ixwebsocket/IXWebSocketTransport.cpp |  | ||||||
|     ixwebsocket/IXWebSocketHandshake.cpp |     ixwebsocket/IXWebSocketHandshake.cpp | ||||||
|  |     ixwebsocket/IXWebSocketHttpHeaders.cpp | ||||||
|  |     ixwebsocket/IXWebSocketMessageQueue.cpp | ||||||
|     ixwebsocket/IXWebSocketPerMessageDeflate.cpp |     ixwebsocket/IXWebSocketPerMessageDeflate.cpp | ||||||
|     ixwebsocket/IXWebSocketPerMessageDeflateCodec.cpp |     ixwebsocket/IXWebSocketPerMessageDeflateCodec.cpp | ||||||
|     ixwebsocket/IXWebSocketPerMessageDeflateOptions.cpp |     ixwebsocket/IXWebSocketPerMessageDeflateOptions.cpp | ||||||
|     ixwebsocket/IXWebSocketHttpHeaders.cpp |     ixwebsocket/IXWebSocketServer.cpp | ||||||
|     ixwebsocket/IXHttpClient.cpp |     ixwebsocket/IXWebSocketTransport.cpp | ||||||
|     ixwebsocket/IXUrlParser.cpp |  | ||||||
|     ixwebsocket/LUrlParser.cpp |     ixwebsocket/LUrlParser.cpp | ||||||
|     ixwebsocket/IXSelectInterrupt.cpp |  | ||||||
|     ixwebsocket/IXSelectInterruptFactory.cpp |  | ||||||
|     ixwebsocket/IXConnectionState.cpp |  | ||||||
|     ixwebsocket/IXWebSocketCloseConstants.cpp |  | ||||||
|     ixwebsocket/IXWebSocketMessageQueue.cpp |  | ||||||
| ) | ) | ||||||
|  |  | ||||||
| set( IXWEBSOCKET_HEADERS | set( IXWEBSOCKET_HEADERS | ||||||
|     ixwebsocket/IXSocket.h |  | ||||||
|     ixwebsocket/IXSocketServer.h |  | ||||||
|     ixwebsocket/IXSocketConnect.h |  | ||||||
|     ixwebsocket/IXSocketFactory.h |  | ||||||
|     ixwebsocket/IXSetThreadName.h |  | ||||||
|     ixwebsocket/IXDNSLookup.h |  | ||||||
|     ixwebsocket/IXCancellationRequest.h |     ixwebsocket/IXCancellationRequest.h | ||||||
|  |     ixwebsocket/IXConnectionState.h | ||||||
|  |     ixwebsocket/IXDNSLookup.h | ||||||
|  |     ixwebsocket/IXHttpClient.h | ||||||
|     ixwebsocket/IXNetSystem.h |     ixwebsocket/IXNetSystem.h | ||||||
|     ixwebsocket/IXProgressCallback.h |     ixwebsocket/IXProgressCallback.h | ||||||
|  |     ixwebsocket/IXSelectInterrupt.h | ||||||
|  |     ixwebsocket/IXSelectInterruptFactory.h | ||||||
|  |     ixwebsocket/IXSetThreadName.h | ||||||
|  |     ixwebsocket/IXSocket.h | ||||||
|  |     ixwebsocket/IXSocketConnect.h | ||||||
|  |     ixwebsocket/IXSocketFactory.h | ||||||
|  |     ixwebsocket/IXSocketServer.h | ||||||
|  |     ixwebsocket/IXUrlParser.h | ||||||
|     ixwebsocket/IXWebSocket.h |     ixwebsocket/IXWebSocket.h | ||||||
|     ixwebsocket/IXWebSocketServer.h |     ixwebsocket/IXWebSocketCloseConstants.h | ||||||
|     ixwebsocket/IXWebSocketTransport.h |  | ||||||
|     ixwebsocket/IXWebSocketHandshake.h |  | ||||||
|     ixwebsocket/IXWebSocketSendInfo.h |  | ||||||
|     ixwebsocket/IXWebSocketErrorInfo.h |  | ||||||
|     ixwebsocket/IXWebSocketCloseInfo.h |     ixwebsocket/IXWebSocketCloseInfo.h | ||||||
|     ixwebsocket/IXWebSocketOpenInfo.h |     ixwebsocket/IXWebSocketErrorInfo.h | ||||||
|     ixwebsocket/IXWebSocketMessageType.h |     ixwebsocket/IXWebSocketHandshake.h | ||||||
|  |     ixwebsocket/IXWebSocketHttpHeaders.h | ||||||
|     ixwebsocket/IXWebSocketMessage.h |     ixwebsocket/IXWebSocketMessage.h | ||||||
|  |     ixwebsocket/IXWebSocketMessageQueue.h | ||||||
|  |     ixwebsocket/IXWebSocketMessageType.h | ||||||
|  |     ixwebsocket/IXWebSocketOpenInfo.h | ||||||
|     ixwebsocket/IXWebSocketPerMessageDeflate.h |     ixwebsocket/IXWebSocketPerMessageDeflate.h | ||||||
|     ixwebsocket/IXWebSocketPerMessageDeflateCodec.h |     ixwebsocket/IXWebSocketPerMessageDeflateCodec.h | ||||||
|     ixwebsocket/IXWebSocketPerMessageDeflateOptions.h |     ixwebsocket/IXWebSocketPerMessageDeflateOptions.h | ||||||
|     ixwebsocket/IXWebSocketHttpHeaders.h |     ixwebsocket/IXWebSocketSendInfo.h | ||||||
|     ixwebsocket/libwshandshake.hpp |     ixwebsocket/IXWebSocketServer.h | ||||||
|     ixwebsocket/IXHttpClient.h |     ixwebsocket/IXWebSocketTransport.h | ||||||
|     ixwebsocket/IXUrlParser.h |  | ||||||
|     ixwebsocket/LUrlParser.h |     ixwebsocket/LUrlParser.h | ||||||
|     ixwebsocket/IXSelectInterrupt.h |     ixwebsocket/libwshandshake.hpp | ||||||
|     ixwebsocket/IXSelectInterruptFactory.h |  | ||||||
|     ixwebsocket/IXConnectionState.h |  | ||||||
|     ixwebsocket/IXWebSocketCloseConstants.h |  | ||||||
|     ixwebsocket/IXWebSocketMessageQueue.h |  | ||||||
| ) | ) | ||||||
|  |  | ||||||
| if (UNIX) | if (UNIX) | ||||||
| @@ -141,25 +143,28 @@ if (USE_OPEN_SSL) | |||||||
| endif() | endif() | ||||||
|  |  | ||||||
| if (USE_MBED_TLS) | if (USE_MBED_TLS) | ||||||
|  |   if (USE_VENDORED_THIRD_PARTY) | ||||||
|     set (ENABLE_PROGRAMS OFF) |     set (ENABLE_PROGRAMS OFF) | ||||||
|     add_subdirectory(third_party/mbedtls) |     add_subdirectory(third_party/mbedtls) | ||||||
|     include_directories(third_party/mbedtls/include) |     include_directories(third_party/mbedtls/include) | ||||||
|  |  | ||||||
|     target_link_libraries(ixwebsocket mbedtls) |     target_link_libraries(ixwebsocket mbedtls) | ||||||
|  |   else() | ||||||
|  |     find_package(MbedTLS REQUIRED) | ||||||
|  |     include_directories(${MBEDTLS_INCLUDE_DIRS}) | ||||||
|  |     target_link_libraries(ixwebsocket ${MBEDTLS_LIBRARIES}) | ||||||
|  |   endif() | ||||||
| endif() | endif() | ||||||
|  |  | ||||||
| if (WIN32) | find_package(ZLIB REQUIRED) | ||||||
|  | if (ZLIB_FOUND) | ||||||
|  |   include_directories(${ZLIB_INCLUDE_DIRS}) | ||||||
|  |   target_link_libraries(ixwebsocket ${ZLIB_LIBRARIES}) | ||||||
|  | else() | ||||||
|   add_subdirectory(third_party/zlib) |   add_subdirectory(third_party/zlib) | ||||||
|   include_directories(third_party/zlib ${CMAKE_CURRENT_BINARY_DIR}/third_party/zlib) |   include_directories(third_party/zlib ${CMAKE_CURRENT_BINARY_DIR}/third_party/zlib) | ||||||
|   target_link_libraries(ixwebsocket zlibstatic wsock32 ws2_32) |   target_link_libraries(ixwebsocket zlibstatic wsock32 ws2_32) | ||||||
|   add_definitions(-D_CRT_SECURE_NO_WARNINGS) |   add_definitions(-D_CRT_SECURE_NO_WARNINGS) | ||||||
|  |  | ||||||
| else() |  | ||||||
|   # gcc/Linux needs -pthread |  | ||||||
|   find_package(Threads) |  | ||||||
|  |  | ||||||
|   target_link_libraries(ixwebsocket  |  | ||||||
|     z ${CMAKE_THREAD_LIBS_INIT}) |  | ||||||
| endif() | endif() | ||||||
|  |  | ||||||
| set( IXWEBSOCKET_INCLUDE_DIRS | set( IXWEBSOCKET_INCLUDE_DIRS | ||||||
| @@ -171,7 +176,7 @@ if (CMAKE_CXX_COMPILER_ID MATCHES "MSVC") | |||||||
|     target_compile_options(ixwebsocket PRIVATE /MP) |     target_compile_options(ixwebsocket PRIVATE /MP) | ||||||
| endif() | endif() | ||||||
|  |  | ||||||
| target_include_directories( ixwebsocket PUBLIC ${IXWEBSOCKET_INCLUDE_DIRS} ) | target_include_directories(ixwebsocket PUBLIC ${IXWEBSOCKET_INCLUDE_DIRS}) | ||||||
|  |  | ||||||
| set_target_properties(ixwebsocket PROPERTIES PUBLIC_HEADER "${IXWEBSOCKET_HEADERS}") | set_target_properties(ixwebsocket PROPERTIES PUBLIC_HEADER "${IXWEBSOCKET_HEADERS}") | ||||||
|  |  | ||||||
|   | |||||||
							
								
								
									
										83
									
								
								README.md
									
									
									
									
									
								
							
							
						
						
									
										83
									
								
								README.md
									
									
									
									
									
								
							| @@ -33,27 +33,22 @@ webSocket.disablePerMessageDeflate(); | |||||||
|  |  | ||||||
| // Setup a callback to be fired when a message or an event (open, close, error) is received | // Setup a callback to be fired when a message or an event (open, close, error) is received | ||||||
| webSocket.setOnMessageCallback( | webSocket.setOnMessageCallback( | ||||||
|     [](ix::WebSocketMessageType messageType, |     [](const ix::WebSocketMessagePtr& msg) | ||||||
|        const std::string& str, |  | ||||||
|        size_t wireSize, |  | ||||||
|        const ix::WebSocketErrorInfo& error, |  | ||||||
|        const ix::WebSocketOpenInfo& openInfo, |  | ||||||
|        const ix::WebSocketCloseInfo& closeInfo) |  | ||||||
|     { |     { | ||||||
|         if (messageType == ix::WebSocketMessageType::Message) |         if (msg->type == ix::WebSocketMessageType::Message) | ||||||
|         { |         { | ||||||
|             std::cout << str << std::endl; |             std::cout << msg->str << std::endl; | ||||||
|         } |         } | ||||||
| }); | }); | ||||||
|  |  | ||||||
| // Now that our callback is setup, we can start our background thread and receive messages | // Now that our callback is setup, we can start our background thread and receive messages | ||||||
| webSocket.start(); | webSocket.start(); | ||||||
|  |  | ||||||
| // Send a message to the server (default to BINARY mode) | // Send a message to the server (default to TEXT mode) | ||||||
| webSocket.send("hello world"); | webSocket.send("hello world"); | ||||||
|  |  | ||||||
| // The message can be sent in TEXT mode | // The message can be sent in BINARY mode (useful if you send MsgPack data for example) | ||||||
| webSocket.sendText("hello again"); | webSocket.sendBinary("some serialized binary data"); | ||||||
|  |  | ||||||
| // ... finally ... | // ... finally ... | ||||||
|  |  | ||||||
| @@ -73,14 +68,9 @@ server.setOnConnectionCallback( | |||||||
|               std::shared_ptr<ConnectionState> connectionState) |               std::shared_ptr<ConnectionState> connectionState) | ||||||
|     { |     { | ||||||
|         webSocket->setOnMessageCallback( |         webSocket->setOnMessageCallback( | ||||||
|             [webSocket, connectionState, &server](ix::WebSocketMessageType messageType, |             [webSocket, connectionState, &server](const ix::WebSocketMessagePtr msg) | ||||||
|                const std::string& str, |  | ||||||
|                size_t wireSize, |  | ||||||
|                const ix::WebSocketErrorInfo& error, |  | ||||||
|                const ix::WebSocketOpenInfo& openInfo, |  | ||||||
|                const ix::WebSocketCloseInfo& closeInfo) |  | ||||||
|             { |             { | ||||||
|                 if (messageType == ix::WebSocketMessageType::Open) |                 if (msg->type == ix::WebSocketMessageType::Open) | ||||||
|                 { |                 { | ||||||
|                     std::cerr << "New connection" << std::endl; |                     std::cerr << "New connection" << std::endl; | ||||||
|  |  | ||||||
| @@ -91,19 +81,21 @@ server.setOnConnectionCallback( | |||||||
|                     std::cerr << "id: " << connectionState->getId() << std::endl; |                     std::cerr << "id: " << connectionState->getId() << std::endl; | ||||||
|  |  | ||||||
|                     // The uri the client did connect to. |                     // The uri the client did connect to. | ||||||
|                     std::cerr << "Uri: " << openInfo.uri << std::endl; |                     std::cerr << "Uri: " << msg->openInfo.uri << std::endl; | ||||||
|  |  | ||||||
|                     std::cerr << "Headers:" << std::endl; |                     std::cerr << "Headers:" << std::endl; | ||||||
|                     for (auto it : openInfo.headers) |                     for (auto it : msg->openInfo.headers) | ||||||
|                     { |                     { | ||||||
|                         std::cerr << it.first << ": " << it.second << std::endl; |                         std::cerr << it.first << ": " << it.second << std::endl; | ||||||
|                     } |                     } | ||||||
|                 } |                 } | ||||||
|                 else if (messageType == ix::WebSocketMessageType::Message) |                 else if (msg->type == ix::WebSocketMessageType::Message) | ||||||
|                 { |                 { | ||||||
|                     // For an echo server, we just send back to the client whatever was received by the server |                     // For an echo server, we just send back to the client whatever was received by the server | ||||||
|                     // All connected clients are available in an std::set. See the broadcast cpp example. |                     // All connected clients are available in an std::set. See the broadcast cpp example. | ||||||
|                     webSocket->send(str); |                     // Second parameter tells whether we are sending the message in binary or text mode. | ||||||
|  |                     // Here we send it in the same mode as it was received. | ||||||
|  |                     webSocket->send(msg->str, msg->binary); | ||||||
|                 } |                 } | ||||||
|             } |             } | ||||||
|         ); |         ); | ||||||
| @@ -334,32 +326,27 @@ The onMessage event will be fired when the connection is opened or closed. This | |||||||
|  |  | ||||||
| ``` | ``` | ||||||
| webSocket.setOnMessageCallback( | webSocket.setOnMessageCallback( | ||||||
|     [](ix::WebSocketMessageType messageType, |     [](const ix::WebSocketMessagePtr& msg) | ||||||
|        const std::string& str, |  | ||||||
|        size_t wireSize, |  | ||||||
|        const ix::WebSocketErrorInfo& error, |  | ||||||
|        const ix::WebSocketOpenInfo& openInfo, |  | ||||||
|        const ix::WebSocketCloseInfo& closeInfo) |  | ||||||
|     { |     { | ||||||
|         if (messageType == ix::WebSocketMessageType::Open) |         if (msg->type == ix::WebSocketMessageType::Open) | ||||||
|         { |         { | ||||||
|             std::cout << "send greetings" << std::endl; |             std::cout << "send greetings" << std::endl; | ||||||
|  |  | ||||||
|             // Headers can be inspected (pairs of string/string) |             // Headers can be inspected (pairs of string/string) | ||||||
|             std::cout << "Handshake Headers:" << std::endl; |             std::cout << "Handshake Headers:" << std::endl; | ||||||
|             for (auto it : headers) |             for (auto it : msg->headers) | ||||||
|             { |             { | ||||||
|                 std::cout << it.first << ": " << it.second << std::endl; |                 std::cout << it.first << ": " << it.second << std::endl; | ||||||
|             } |             } | ||||||
|         } |         } | ||||||
|         else if (messageType == ix::WebSocketMessageType::Close) |         else if (msg->type == ix::WebSocketMessageType::Close) | ||||||
|         { |         { | ||||||
|             std::cout << "disconnected" << std::endl; |             std::cout << "disconnected" << std::endl; | ||||||
|  |  | ||||||
|             // The server can send an explicit code and reason for closing. |             // The server can send an explicit code and reason for closing. | ||||||
|             // This data can be accessed through the closeInfo object. |             // This data can be accessed through the closeInfo object. | ||||||
|             std::cout << closeInfo.code << std::endl; |             std::cout << msg->closeInfo.code << std::endl; | ||||||
|             std::cout << closeInfo.reason << std::endl; |             std::cout << msg->closeInfo.reason << std::endl; | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
| ); | ); | ||||||
| @@ -371,20 +358,15 @@ A message will be fired when there is an error with the connection. The message | |||||||
|  |  | ||||||
| ``` | ``` | ||||||
| webSocket.setOnMessageCallback( | webSocket.setOnMessageCallback( | ||||||
|     [](ix::WebSocketMessageType messageType, |     [](const ix::WebSocketMessagePtr& msg) | ||||||
|        const std::string& str, |  | ||||||
|        size_t wireSize, |  | ||||||
|        const ix::WebSocketErrorInfo& error, |  | ||||||
|        const ix::WebSocketOpenInfo& openInfo, |  | ||||||
|        const ix::WebSocketCloseInfo& closeInfo) |  | ||||||
|     { |     { | ||||||
|         if (messageType == ix::WebSocketMessageType::Error) |         if (msg->type == ix::WebSocketMessageType::Error) | ||||||
|         { |         { | ||||||
|             std::stringstream ss; |             std::stringstream ss; | ||||||
|             ss << "Error: "         << error.reason      << std::endl; |             ss << "Error: "         << msg->errorInfo.reason      << std::endl; | ||||||
|             ss << "#retries: "      << event.retries     << std::endl; |             ss << "#retries: "      << msg->eventInfo.retries     << std::endl; | ||||||
|             ss << "Wait time(ms): " << event.wait_time   << std::endl; |             ss << "Wait time(ms): " << msg->eventInfo.wait_time   << std::endl; | ||||||
|             ss << "HTTP Status: "   << event.http_status << std::endl; |             ss << "HTTP Status: "   << msg->eventInfo.http_status << std::endl; | ||||||
|             std::cout << ss.str() << std::endl; |             std::cout << ss.str() << std::endl; | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
| @@ -411,17 +393,12 @@ Ping/pong messages are used to implement keep-alive. 2 message types exists to i | |||||||
|  |  | ||||||
| ``` | ``` | ||||||
| webSocket.setOnMessageCallback( | webSocket.setOnMessageCallback( | ||||||
|     [](ix::WebSocketMessageType messageType, |     [](const ix::WebSocketMessagePtr& msg) | ||||||
|        const std::string& str, |  | ||||||
|        size_t wireSize, |  | ||||||
|        const ix::WebSocketErrorInfo& error, |  | ||||||
|        const ix::WebSocketOpenInfo& openInfo, |  | ||||||
|        const ix::WebSocketCloseInfo& closeInfo) |  | ||||||
|     { |     { | ||||||
|         if (messageType == ix::WebSocketMessageType::Ping || |         if (msg->type == ix::WebSocketMessageType::Ping || | ||||||
|             messageType == ix::WebSocketMessageType::Pong) |             msg->type == ix::WebSocketMessageType::Pong) | ||||||
|         { |         { | ||||||
|             std::cout << "pong data: " << str << std::endl; |             std::cout << "pong data: " << msg->str << std::endl; | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
| ); | ); | ||||||
|   | |||||||
							
								
								
									
										2
									
								
								makefile
									
									
									
									
									
								
							
							
						
						
									
										2
									
								
								makefile
									
									
									
									
									
								
							| @@ -12,7 +12,7 @@ brew: | |||||||
| 	mkdir -p build && (cd build ; cmake -DUSE_TLS=1 -DUSE_WS=1 .. ; make -j install) | 	mkdir -p build && (cd build ; cmake -DUSE_TLS=1 -DUSE_WS=1 .. ; make -j install) | ||||||
|  |  | ||||||
| ws: | ws: | ||||||
| 	mkdir -p build && (cd build ; cmake -DUSE_TLS=1 -DUSE_WS=1 -DUSE_MBED_TLS=1 .. ; make -j) | 	mkdir -p build && (cd build ; cmake -DUSE_TLS=1 -DUSE_WS=1 -DUSE_MBED_TLS=1 -DUSE_VENDORED_THIRD_PARTY=1 .. ; make -j) | ||||||
|  |  | ||||||
| uninstall: | uninstall: | ||||||
| 	xargs rm -fv < build/install_manifest.txt | 	xargs rm -fv < build/install_manifest.txt | ||||||
|   | |||||||
| @@ -200,7 +200,7 @@ namespace ix | |||||||
|                             { |                             { | ||||||
|                                 if (client != webSocket) |                                 if (client != webSocket) | ||||||
|                                 { |                                 { | ||||||
|                                     client->send(msg->str); |                                     client->send(msg->str, msg->binary); | ||||||
|                                 } |                                 } | ||||||
|                             } |                             } | ||||||
|                         } |                         } | ||||||
|   | |||||||
| @@ -30,7 +30,7 @@ namespace | |||||||
|                     Logger() << "New connection"; |                     Logger() << "New connection"; | ||||||
|                     connectionState->computeId(); |                     connectionState->computeId(); | ||||||
|                     Logger() << "id: " << connectionState->getId(); |                     Logger() << "id: " << connectionState->getId(); | ||||||
|                     Logger() << "Uri: " << openInfo.uri; |                     Logger() << "Uri: " << msg->openInfo.uri; | ||||||
|                     Logger() << "Headers:"; |                     Logger() << "Headers:"; | ||||||
|                     for (auto&& it : msg->openInfo.headers) |                     for (auto&& it : msg->openInfo.headers) | ||||||
|                     { |                     { | ||||||
| @@ -43,11 +43,11 @@ namespace | |||||||
|                 } |                 } | ||||||
|                 else if (msg->type == ix::WebSocketMessageType::Message) |                 else if (msg->type == ix::WebSocketMessageType::Message) | ||||||
|                 { |                 { | ||||||
|                     Logger() << "Message received: " << str; |                     Logger() << "Message received: " << msg->str; | ||||||
|  |  | ||||||
|                     for (auto&& client : server.getClients()) |                     for (auto&& client : server.getClients()) | ||||||
|                     { |                     { | ||||||
|                         client->send(str); |                         client->send(msg->str); | ||||||
|                     } |                     } | ||||||
|                 } |                 } | ||||||
|             } |             } | ||||||
| @@ -89,25 +89,25 @@ namespace | |||||||
|                 } |                 } | ||||||
|                 else if (msg->type == WebSocketMessageType::Error) |                 else if (msg->type == WebSocketMessageType::Error) | ||||||
|                 { |                 { | ||||||
|                     ss << "Error ! " << error.reason; |                     ss << "Error ! " << msg->errorInfo.reason; | ||||||
|                     log(ss.str()); |                     log(ss.str()); | ||||||
|                     testDone = true; |                     testDone = true; | ||||||
|                 } |                 } | ||||||
|                 else if (msg->type == WebSocketMessageType::Pong) |                 else if (msg->type == WebSocketMessageType::Pong) | ||||||
|                 { |                 { | ||||||
|                     ss << "Received pong message " << str; |                     ss << "Received pong message " << msg->str; | ||||||
|                     log(ss.str()); |                     log(ss.str()); | ||||||
|                 } |                 } | ||||||
|                 else if (msg->type == WebSocketMessageType::Ping) |                 else if (msg->type == WebSocketMessageType::Ping) | ||||||
|                 { |                 { | ||||||
|                     ss << "Received ping message " << str; |                     ss << "Received ping message " << msg->str; | ||||||
|                     log(ss.str()); |                     log(ss.str()); | ||||||
|                 } |                 } | ||||||
|                 else if (msg->type == WebSocketMessageType::Message) |                 else if (msg->type == WebSocketMessageType::Message) | ||||||
|                 { |                 { | ||||||
|                     REQUIRE(str.compare("Hey dude!") == 0); |                     REQUIRE(msg->str.compare("Hey dude!") == 0); | ||||||
|                     ++receivedCount; |                     ++receivedCount; | ||||||
|                     ss << "Received message " << str; |                     ss << "Received message " << msg->str; | ||||||
|                     log(ss.str()); |                     log(ss.str()); | ||||||
|                     sendNextMessage(); |                     sendNextMessage(); | ||||||
|                 } |                 } | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user