POCO C++ 라이브러리 에코 서버 구현하기
C++ 라이브러리인 POCO의 벤치마크를 위해 에코서버 예제를 찾았다.
깃헙 https://github.com/pocoproject/poco
포코 설치 및 실행 매뉴얼 https://pocoproject.org/docs/00200-GettingStarted.html
이 예제를 통해 오픈소스로 돌아다니는 C++ 프로젝트 정도는 쉽게 해결할 수 있을 것이다.
- 라이브러리 컴파일 및 설치하기
깃헙에서 프로젝트를 받아와 프로젝트 폴더로 이동한다.
git clone https://github.com/pocoproject/poco cd poco
포코는 make 3.8 버전 이상만 컴파일 된다. make 버전을 확인하고 필요시 업데이트할 것
$ make —version
configure 스크립트를 실행한 후 make install 진행. make에는 ~10분 정도 시간이 걸린듯
$ ./configure $ sudo make -s install
이 때 configure 커맨드에 —omit 옵션을 추가하여, 필요없는 기능을 제외할 수 있다. 나에겐 DB 관련 컴포넌트가 필요없어 이들을 제외했다.
./configure —omit=SQL/ODBC,SQL/MySQL,SQL/PostgreSQL
- EchoServer 예제 실행하기
이렇게 설치해서 만들어지는 poco 프로젝트 구성은 다음과 같다.
build/ the build system for Unix and additional utility scripts config/ build configurations for various Unix platforms rules/ common build rules for all platforms scripts/ build and utility scripts vxconfig/ VxWorks build configurations
…(중략)…
Net/ project and make/build files for the Net library include/ Poco/ Net/ header files for the Net library src/ source files for the Net library testsuite/ project and make/build files for the Net testsuite src/ source files for the Net testsuite bin/ test suite executables samples/ sample applications for the Net library
에코 서버의 실행을 위해 samples 디렉토리로 가서 EchoServer.o 파일을 찾아야 한다. 손으로 찾기가 귀찮아서 find 커맨드를 이용했다.
에코 서버의 바이너리가 어딨는지 찾아보자 ❯ find -name ‘EchoServer’ ./samples/EchoServer ./samples/EchoServer/bin/Linux/x86_64/EchoServer
바이너리는 저깄구나. 그럼 오브젝트 파일은 어딨는가? $ find -name ‘Echo*.o’ ./Net/testsuite/obj/Linux/x86_64/release_shared/EchoServer.o ./Net/testsuite/obj/Linux/x86_64/debug_shared/EchoServer.o ./Net/samples/EchoServer/obj/Linux/x86_64/release_shared/EchoServer.o ./Net/samples/EchoServer/obj/Linux/x86_64/debug_shared/EchoServer.o
testsuite는 테스트용 프로젝트이고, EchoServer가 에코용 프로젝트임을 알 수 있다.
바이너리 파일을 실행하면 에코 서버가 실행된다.
$ ./samples/EchoServer/bin/Linux/x86_64/EchoServer
(이 에코 프로그램은 시작할 때 터미널에 출력하는 내용이 없음)
이제 텔넷이나 jmeter로 tcp로 메세지를 쏴주면 에코로 응답을 해준다.
포트는 9977이 디폴트 값으로 되어 있었다. 필요하다면 소스코드에서 바꿀 수 있다.