(주요 개발자의 메모에 주목할 때, 슬프게도 더 이상이 라이브러리에 헌신 할 시간이 너무 많지 않습니다. 아마도 다른 사람에게 더 동기를 부여 할 때가되었을까요?)
ixwebsocket은 WebSocket 클라이언트 및 서버 개발을위한 C ++ 라이브러리입니다. 최소 의존성 (부스트 없음)을 가지고 있으며 사용하기가 매우 간단하며 WebSocke Dev (SSL, Deflate Compression, 대부분의 플랫폼에서 컴파일 등)에 필요한 모든 것을 지원합니다. HTTP 클라이언트 및 서버 코드도 사용할 수 있지만 테스트를 많이받지 못했습니다.
2017 년부터 많은 메시지를 보내고 수신하는 큰 모바일 비디오 게임 타이틀에 사용되었습니다 (iOS 및 Android). MacOS, iOS, Linux, Android, Windows 및 FreeBSD에서 테스트되었습니다. 두 가지 중요한 설계 목표는 단순성과 정확성입니다.
/*
* main.cpp
* Author: Benjamin Sergeant
* Copyright (c) 2020 Machine Zone, Inc. All rights reserved.
*
* Super simple standalone example. See ws folder, unittest and doc/usage.md for more.
*
* On macOS
* $ mkdir -p build ; (cd build ; cmake -DUSE_TLS=1 .. ; make -j ; make install)
* $ clang++ --std=c++11 --stdlib=libc++ main.cpp -lixwebsocket -lz -framework Security -framework Foundation
* $ ./a.out
*
* Or use cmake -DBUILD_DEMO=ON option for other platforms
*/
# include < ixwebsocket/IXNetSystem.h >
# include < ixwebsocket/IXWebSocket.h >
# include < ixwebsocket/IXUserAgent.h >
# include < iostream >
int main ()
{
// Required on Windows
ix::initNetSystem ();
// Our websocket object
ix::WebSocket webSocket;
// Connect to a server with encryption
// See https://machinezone.github.io/IXWebSocket/usage/#tls-support-and-configuration
// https://github.com/machinezone/IXWebSocket/issues/386#issuecomment-1105235227 (self signed certificates)
std::string url ( " wss://echo.websocket.org " );
webSocket. setUrl (url);
std::cout << " Connecting to " << url << " ... " << std::endl;
// Setup a callback to be fired (in a background thread, watch out for race conditions !)
// when a message or an event (open, close, error) is received
webSocket. setOnMessageCallback ([]( const ix::WebSocketMessagePtr& msg)
{
if (msg-> type == ix::WebSocketMessageType::Message)
{
std::cout << " received message: " << msg-> str << std::endl;
std::cout << " > " << std::flush;
}
else if (msg-> type == ix::WebSocketMessageType::Open)
{
std::cout << " Connection established " << std::endl;
std::cout << " > " << std::flush;
}
else if (msg-> type == ix::WebSocketMessageType::Error)
{
// Maybe SSL is not configured properly
std::cout << " Connection error: " << msg-> errorInfo . reason << std::endl;
std::cout << " > " << std::flush;
}
}
);
// Now that our callback is setup, we can start our background thread and receive messages
webSocket. start ();
// Send a message to the server (default to TEXT mode)
webSocket. send ( " hello world " );
// Display a prompt
std::cout << " > " << std::flush;
std::string text;
// Read text from the console and send messages in text mode.
// Exit with Ctrl-D on Unix or Ctrl-Z on Windows.
while ( std::getline (std::cin, text))
{
webSocket. send (text);
std::cout << " > " << std::flush;
}
return 0 ;
}관심 있는? 문서를 읽으십시오! 상황이 예상대로 작동하지 않으면 GitHub에서 문제를 만들거나 문제를 해결하는 방법을 알고 있다면 풀 요청을 더 잘 작성하십시오.
ixwebsocket은 적극적으로 개발 중입니다. Changelog를 확인하여 요리가 무엇인지 확인하십시오. Redis가 뒷받침하는 History와 같은 많은 기능을 사용하여 실시간 메시징 서비스 (Chat-Like 'Server'귀하의 WebSocket 코드와 대화 할 것입니다)를 찾고 있다면 Cobra를보십시오.
ixwebsocket 클라이언트 코드는 6.0.0 버전으로 시작하는 Autobahn을 준수합니다. 현재 테스트 결과를 참조하십시오. 서버 코드에서는 일부 테스트가 여전히 실패하고 있습니다.
11.0.8 릴리스부터 ixwebsocket은 완전히 C ++ 11 호환되어야합니다.
회사 나 프로젝트 가이 라이브러리를 사용하는 경우이 목록을 수정하기 위해 문제 나 PR을 자유롭게 열어주십시오.
훌륭한 WebSocket 라이브러리가 많이 있습니다. 다음은 몇 가지 진지한 것들이 있습니다.
UVWeb는 ixwebsocket 저자가 작성한 라이브러리로 UVW 위에 제작 된 Libuv의 C ++ 래퍼입니다. 이 시점에서는 종속성이 많고 SSL을 지원하지 않지만 Libuv 덕분에 단일 OS 스레드 내에서 여러 연결을 열는 데 사용할 수 있습니다.
WebSocket 라이브러리의 성능을 확인하려면 Autoroute 프로젝트를 볼 수 있습니다.
| OS | TLS | 소독제 | 상태 |
|---|---|---|---|
| 리눅스 | OpenSSL | 없음 | |
| 마코스 | 안전한 운송 | 스레드 소독제 | |
| 마코스 | OpenSSL | 스레드 소독제 | |
| 마코스 | mbedtls | 스레드 소독제 | |
| 창 | 장애가 있는 | 없음 | |
| UWP | 장애가 있는 | 없음 | |
| 리눅스 | OpenSSL | 소독제 주소 |