Skip to content

Commit 03a47c7

Browse files
committed
translate to eng
1 parent f658196 commit 03a47c7

6 files changed

Lines changed: 94 additions & 51 deletions

File tree

CMakeLists.txt

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,26 @@
11
cmake_minimum_required(VERSION 3.10)
22
project(ix_websocket_example)
33

4-
# C++ 표준 설정
4+
# Set C++ standard
55
set(CMAKE_CXX_STANDARD 17)
66
set(CMAKE_CXX_STANDARD_REQUIRED ON)
77

8-
# IXWebSocket 패키지 찾기
9-
# 시스템에 설치되어 있거나 vcpkg 등을 통해 경로가 잡혀있어야 합니다.
10-
# https://github.com/machinezone/IXWebSocket 의 사전 설치 필요함.
8+
# Find IXWebSocket package
9+
# Must be installed on the system or have its path provided via vcpkg, etc.
10+
# Pre-installation of https://github.com/machinezone/IXWebSocket is required.
1111
find_package(ixwebsocket REQUIRED)
1212

13-
# 실행 파일 생성
13+
# Create executable
1414
add_executable(ws_client
1515
main.cpp
1616
custom_websocket_client.cpp
1717
)
1818

19-
# 헤더 경로 및 라이브러리 링크
19+
# Header paths and library linking
2020
target_include_directories(ws_client PRIVATE ${CMAKE_CURRENT_SOURCE_DIR})
21-
target_link_libraries(ws_client PRIVATE ixwebsocket::ixwebsocket) # IXWebSocket 라이브러리 링크.
21+
target_link_libraries(ws_client PRIVATE ixwebsocket::ixwebsocket) # Link IXWebSocket library.
2222

23-
# 시스템 라이브러리 링크 (Linux의 경우 Threads, SSL 등 필요)
23+
# Link system libraries (Threads, SSL, etc. may be required on Linux)
2424
find_package(Threads REQUIRED)
2525
target_link_libraries(ws_client PRIVATE Threads::Threads)
2626

README.ko.md

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# custom_websocket_client
2+
3+
> [English](README.md)
4+
5+
## 소개
6+
`custom_websocket_client`[IXWebSocket](https://github.com/machinezone/IXWebSocket) 라이브러리를 기반으로 제작된 C++ 웹소켓 클라이언트 예제입니다. 간단한 코드로 웹소켓 서버와의 연결, 메시지 송수신, 쓰레드 안전 송신 등을 구현할 수 있습니다.
7+
8+
## 주요 기능
9+
- 웹소켓 서버 연결 및 해제
10+
- 텍스트/바이너리 메시지 송수신
11+
- 쓰레드 안전한 메시지 전송
12+
- 연결 상태 및 오류 출력
13+
14+
## 빌드 방법
15+
1. **IXWebSocket 라이브러리 설치**
16+
- vcpkg, 소스 빌드 등으로 [IXWebSocket](https://github.com/machinezone/IXWebSocket)을 설치하세요.
17+
2. **CMake 빌드**
18+
```bash
19+
mkdir build
20+
cd build
21+
cmake ..
22+
cmake --build .
23+
```
24+
25+
## 실행 방법
26+
빌드 후 생성된 실행 파일(`ws_client`)을 사용합니다.
27+
28+
```bash
29+
./ws_client
30+
```
31+
32+
프로그램 실행 후 메시지를 입력하면 서버로 전송되며, 서버로부터 수신된 메시지는 콘솔에 출력됩니다. 종료하려면 `exit`을 입력하세요.
33+
34+
## 의존성
35+
- [IXWebSocket](https://github.com/machinezone/IXWebSocket)
36+
- C++17 이상
37+
- CMake 3.10 이상
38+
- (Linux) OpenSSL, pthread 등
39+
40+
## 라이선스
41+
MIT License (LICENSE 파일 참고)

README.md

Lines changed: 24 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,41 @@
11
# custom_websocket_client
22

3-
## 소개
4-
`custom_websocket_client`[IXWebSocket](https://github.com/machinezone/IXWebSocket) 라이브러리를 기반으로 제작된 C++ 웹소켓 클라이언트 예제입니다. 간단한 코드로 웹소켓 서버와의 연결, 메시지 송수신, 쓰레드 안전 송신 등을 구현할 수 있습니다.
5-
6-
## 주요 기능
7-
- 웹소켓 서버 연결 및 해제
8-
- 텍스트/바이너리 메시지 송수신
9-
- 쓰레드 안전한 메시지 전송
10-
- 연결 상태 및 오류 출력
11-
12-
## 빌드 방법
13-
1. **IXWebSocket 라이브러리 설치**
14-
- vcpkg, 소스 빌드 등으로 [IXWebSocket](https://github.com/machinezone/IXWebSocket)을 설치하세요.
15-
2. **CMake 빌드**
3+
> [Korean](README.ko.md)
4+
5+
## Introduction
6+
`custom_websocket_client` is a C++ WebSocket client example based on the [IXWebSocket](https://github.com/machinezone/IXWebSocket) library. This project demonstrates how to implement connections with a WebSocket server, send and receive messages, and ensure thread-safe transmissions with simple code.
7+
8+
## Key Features
9+
- Connect and disconnect from WebSocket servers
10+
- Send and receive text/binary messages
11+
- Thread-safe message transmission
12+
- Connection status and error reporting
13+
14+
## Build Instructions
15+
1. **Install IXWebSocket Library**
16+
- Install [IXWebSocket](https://github.com/machinezone/IXWebSocket) using vcpkg, source build, or other methods.
17+
2. **CMake Build**
1618
```bash
1719
mkdir build
1820
cd build
1921
cmake ..
2022
cmake --build .
2123
```
2224

23-
## 실행 방법
24-
빌드 후 생성된 실행 파일(`ws_client`)을 사용합니다.
25+
## Usage
26+
Run the generated executable (`ws_client`) after building.
2527

2628
```bash
2729
./ws_client
2830
```
2931

30-
프로그램 실행 후 메시지를 입력하면 서버로 전송되며, 서버로부터 수신된 메시지는 콘솔에 출력됩니다. 종료하려면 `exit`을 입력하세요.
32+
After starting the program, enter a message to send it to the server. Messages received from the server will be displayed in the console. Type `exit` to terminate the program.
3133

32-
## 의존성
34+
## Dependencies
3335
- [IXWebSocket](https://github.com/machinezone/IXWebSocket)
34-
- C++17 이상
35-
- CMake 3.10 이상
36-
- (Linux) OpenSSL, pthread
36+
- C++17 or later
37+
- CMake 3.10 or later
38+
- (Linux) OpenSSL, pthread, etc.
3739

38-
## 라이선스
39-
MIT License (LICENSE 파일 참고)
40+
## License
41+
MIT License (see LICENSE file)

custom_websocket_client.cpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,35 +21,35 @@ void custom_websocket_client::setup_callback() {
2121
switch (msg->type) {
2222
case ix::WebSocketMessageType::Message:
2323
if (msg->binary) {
24-
std::cout << "\n[수신] Binary message size: " << msg->str.size() << " bytes" << std::endl;
24+
std::cout << "\n[RECEIVED] Binary message size: " << msg->str.size() << " bytes" << std::endl;
2525
} else {
26-
std::cout << "\n[수신] Text message: " << msg->str << std::endl;
26+
std::cout << "\n[RECEIVED] Text message: " << msg->str << std::endl;
2727
}
2828
break;
2929

3030
case ix::WebSocketMessageType::Open:
31-
std::cout << "[상태] Connection opened" << std::endl;
31+
std::cout << "[STATUS] Connection opened" << std::endl;
3232
break;
3333

3434
case ix::WebSocketMessageType::Close:
35-
std::cout << "[상태] Connection closed. Code: " << msg->closeInfo.code
35+
std::cout << "[STATUS] Connection closed. Code: " << msg->closeInfo.code
3636
<< ", Reason: " << msg->closeInfo.reason << std::endl;
3737
break;
3838

3939
case ix::WebSocketMessageType::Error:
40-
std::cerr << "[오류] Error: " << msg->errorInfo.reason << std::endl;
40+
std::cerr << "[ERROR] Error: " << msg->errorInfo.reason << std::endl;
4141
break;
4242

4343
case ix::WebSocketMessageType::Ping:
44-
// 서버로부터 수신된 Ping (자동 응답됨)
44+
// Ping received from server (automatically responded)
4545
break;
4646

4747
case ix::WebSocketMessageType::Pong:
48-
// 클라이언트 Ping에 대한 서버의 응답 수신
48+
// Received server's response to client's Ping (Pong)
4949
break;
5050

5151
case ix::WebSocketMessageType::Fragment:
52-
// 파편화된 메시지 수신 시 처리
52+
// Handle reception of fragmented messages
5353
break;
5454
}
5555
});
@@ -66,9 +66,9 @@ void custom_websocket_client::stop() {
6666
void custom_websocket_client::send_message(const std::string& text) {
6767
if (_web_socket.getReadyState() == ix::ReadyState::Open) {
6868
_web_socket.send(text);
69-
std::cout << "[송신] " << text << std::endl;
69+
std::cout << "[SENT] " << text << std::endl;
7070
} else {
71-
std::cerr << "[경고] Cannot send. Connection is not open." << std::endl;
71+
std::cerr << "[WARNING] Cannot send. Connection is not open." << std::endl;
7272
}
7373
}
7474

custom_websocket_client.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,14 @@ class custom_websocket_client {
99
void set_url(const std::string& url);
1010
~custom_websocket_client();
1111

12-
// 서비스 제어
12+
// Service control
1313
void start();
1414
void stop();
1515

16-
// 외부 쓰레드 안전 송신
16+
// Thread-safe sending from external threads
1717
void send_message(const std::string& text);
1818

19-
// 연결 상태 확인
19+
// Check connection status
2020
bool isReady() const;
2121

2222
private:

main.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,33 +5,33 @@
55
int main() {
66
custom_websocket_client client;
77

8-
std::string server_url = "ws://localhost:8080"; // wss:// (WebSocket Secure) 프로토콜도 지원됨.
8+
std::string server_url = "ws://localhost:8080"; // wss:// (WebSocket Secure) protocol is also supported.
99
client.set_url(server_url);
1010

11-
client.start(); // 웹소켓 클라이언트 시작
11+
client.start(); // Start the WebSocket client
1212

1313
std::cout << "--- Enter message to send (type 'exit' to quit) ---" << std::endl;
1414

1515
std::string user_input;
16-
user_input = "hello world"; // 테스트용 초기 메시지
16+
user_input = "hello world"; // Initial test message
1717

1818
while (true) {
1919
// if (!std::getline(std::cin, user_input)) break;
2020
// if (user_input == "exit") break;
2121

2222
if (!user_input.empty()) {
2323
if (client.isReady()) {
24-
std::cout << "[송신] " << user_input << std::endl;
24+
std::cout << "[SEND] " << user_input << std::endl;
2525
client.send_message(user_input);
26-
// 쓰레드 세이프하게 메시지 송신. 외부 쓰레드에서 호출해도 됨.
26+
// Send messages in a thread-safe manner. Can be called from external threads.
2727
} else {
28-
std::cerr << "[경고] Connection is not open. Message will be sent when connection is established." << std::endl;
28+
std::cerr << "[Warning] Connection is not open. Message will be sent when connection is established." << std::endl;
2929
}
3030
}
3131

32-
std::this_thread::sleep_for(std::chrono::milliseconds(1000)); // CPU 과부하 방지 위해 잠시 대기
32+
std::this_thread::sleep_for(std::chrono::milliseconds(1000)); // Brief wait to prevent CPU overuse
3333
}
3434

35-
client.stop(); // 웹소켓 클라이언트 종료
35+
client.stop(); // Stop the WebSocket client
3636
return 0;
3737
}

0 commit comments

Comments
 (0)