한국리눅스유저그룹 위키페이지- LUG KOREA
Kernel News | GNOME News | KDE News | linux.kernel | comp.lang.c++ | wxWidgets GUI | comp.lang.python
 

Sockets 라이브러리를 사용한 C++ 소켓 프로그래밍 분석

CentOS 5.x 에서 소스 파일을 사용한 설치

[root@localhost src]# lftpget http://www.alhem.net/Sockets/Sockets-2.3.tar.gz
[root@localhost src]# tar xzf Sockets-2.3.tar.gz
[root@localhost src]# cd Sockets-2.3
[root@localhost Sockets-2.3]# ls
Ajp13Socket.cpp       HttpdCookies.h                      ResolvSocket.h
Ajp13Socket.h         HttpdForm.cpp                       SSLInitializer.cpp
AjpBaseSocket.cpp     HttpdForm.h                         SSLInitializer.h
AjpBaseSocket.h       HttpdSocket.cpp                     SctpSocket.cpp
Base64.cpp            HttpdSocket.h                       SctpSocket.h
Base64.h              IBase.h                             Semaphore.cpp
Changelog             IEventHandler.h                     Semaphore.h
Debug.cpp             IEventOwner.cpp                     SmtpdSocket.cpp
Debug.h               IEventOwner.h                       SmtpdSocket.h
DevCpp                IFile.h                             Socket.cpp
Event.cpp             IHttpServer.h                       Socket.h
Event.h               INSTALL                             SocketAddress.h
EventHandler.cpp      ISocketHandler.h                    SocketHandler.cpp
EventHandler.h        Ipv4Address.cpp                     SocketHandler.h
EventTime.cpp         Ipv4Address.h                       Sockets-config.cpp
EventTime.h           Ipv6Address.cpp                     StdLog.h
Exception.cpp         Ipv6Address.h                       StdoutLog.cpp
Exception.h           ListenSocket.h                      StdoutLog.h
File.cpp              Lock.cpp                            StreamSocket.cpp
File.h                Lock.h                              StreamSocket.h
HTTPSocket.cpp        Makefile                            TcpSocket.cpp
HTTPSocket.h          Makefile.Defines.linux-x86-32       TcpSocket.h
HttpBaseSocket.cpp    Makefile.Defines.macosx             Thread.cpp
HttpBaseSocket.h      Makefile.Defines.solaris8           Thread.h
HttpClientSocket.cpp  Makefile.Defines.solaris9-sparc-64  UdpSocket.cpp
HttpClientSocket.h    Makefile.Defines.win32-cygwin       UdpSocket.h
HttpDebugSocket.cpp   Makefile.solaris9-sparc-64          Utility.cpp
HttpDebugSocket.h     Makefile.version                    Utility.h
HttpGetSocket.cpp     MemFile.cpp                         XmlDocument.cpp
HttpGetSocket.h       MemFile.h                           XmlDocument.h
HttpPostSocket.cpp    Mutex.cpp                           XmlException.cpp
HttpPostSocket.h      Mutex.h                             XmlException.h
HttpPutSocket.cpp     OSX.zip                             XmlNode.cpp
HttpPutSocket.h       Parse.cpp                           XmlNode.h
HttpRequest.cpp       Parse.h                             ajp13.h
HttpRequest.h         Project                             gpl.txt
HttpResponse.cpp      Project.net                         mkdot.sh
HttpResponse.h        README.macosx                       socket_include.cpp
HttpTransaction.cpp   ResolvServer.cpp                    socket_include.h
HttpTransaction.h     ResolvServer.h                      sockets-config.h
HttpdCookies.cpp      ResolvSocket.cpp                    tests
[root@localhost Sockets-2.3]# cat INSTALL
C++ Sockets Library :: installation instructions


Unix (and Cygwin/Mingw on windows)
==================================

1.  Change the 'PLATFORM =' line in Makefile

    Possible values are
       linux-x86-32
       win32-cygwin
       solaris9-sparc-64
       macosx
       solaris8

2.  If you want to use ssl encrypted socket communication, the library
    has support for the third-party library openssl. If necessary, add
    the following include directory to Makefile:

    INCLUDE = -I<path to openssl>/include

    The openssl include directory contains only one directory named
    'openssl', in which all header files can be found.

    OpenSSL support is enabled by default.

    If you don't need encrypted communications, make sure to comment
    out this line in the file 'sockets-config.h':

    #define HAVE_OPENSSL

3.  If you really need thread-safe dns lookups, and your operating has
    support for *addrinfo and *nameinfo function calls, make sure this
    line in 'sockets-config.h' is commented:

    #define NO_GETADDRINFO

    By default, dns lookups using getaddrinfo/getnameinfo is disabled.

4.  If your operating system supports SCTP, there might be a slight
    chance the sctp code in the library works. Uncomment this line in
    'sockets-config.h' to try:

    //#define USE_SCTP

5.  If you need IPv6 support, uncomment this line in
    'sockets-config.h':

    //#define ENABLE_IPV6

6.  Type 'make'

7.  If all builds ok, you'll find the static library file 'libSockets.a'
    in the build directory.


When compiling the application, any flags used when compiling the library
also needs to be present when including the library .h files. All flags
can be retrieved using the 'Sockets-config' executable. Add something like
this in your Makefile:

CFLAGS += `Sockets-config`
CPPFLAGS += `Sockets-config`

When linking an application using the library, make sure the object and
library files are in correct order on your link command line:

    First:    Application object files
    2nd:       -lSockets
    3rd:      openssl libraries
    Finally:  Everything else, ending with -lpthread


windows
=======

Project files for various IDE's can be found here:

    Project/           Visual studio 6.0
    Project.net/       Visual studio .NET
    DevCpp/            Dev C++

Please see steps 2-5 above for some details on configuring the library.

When linking on cygwin/mingw, add the following libraries:
 -lwsock32
 -lws2_32

[root@localhost Sockets-2.3]#

1. make, make install을 수행하면 /usr/local 아래에 설치된다.

기본설정은 openssl을 사용하도록 구성되어 있다. 여기서는 단지 prefix 옵션이 /usr/local로 되어 있다.

[root@localhost Sockets-2.3]# cat Makefile

# platforms:
#  linux-x86-32
#  win32-cygwin
#  solaris9-sparc-64
#  macosx
#  solaris8
PLATFORM =  linux-x86-32

# .h files installed to $(PREFIX)/include/Sockets
# static lib .a files installed to $(PREFIX)/lib
PREFIX =    /usr/local

[root@localhost Sockets-2.3]# make
...
[root@localhost Sockets-2.3]# make install
cp libSockets.a /usr/local/lib
cp -a *.h /usr/local/include/Sockets
install Sockets-config /usr/local/bin
[root@localhost Sockets-2.3]#

2. Sockets 라이브러리 사용법, 컴파일방법

Sockets 라이브러리를 사용하기 위해서는 #include 헤더파일 을 사용한다.

컴파일시 옵션으로 -I/usr/local/include/Sockets 옵션을 붙여주고

라이브러리 경로와 .a 파일을 링크하도록 -L/usr/local/lib -lSockets -lpthread -lssl -lcrypto 을 입력해준다.

즉, 아래의 형식으로 컴파일 한다.

# g++ [컴파일할 소스파일들] -o [생성될 실행파일] -I/usr/local/include/Sockets -L/usr/local/lib -lSockets -lpthread -lssl -lcrypto

CentOS 5.x 에서 rpmfoge 저장소를 이용한 라이브러리 설치

1. rpmforge 저장소를 사용하도록 rpmforge에서 배포하는 rpm 패키지를 설치한다.

2. csockets 패키지를 설치한다.

위에서 자신의 서버에 맞는 rpm 파일을 설치하고 yum 으로 아래 두개의 라이브러리를 설치한다.

# yum install csockets csockets-devel

설치 후의 라이브러리 위치

.h 헤더파일 file : /usr/include/Sockets

.a 라이브러리 file : /usr/lib/libSockets.a

Sockets 라이브러리 구조

 
cpp/sockets.txt · 마지막 수정: 2008/07/28 01:40 작성자 multi
 
이 위키의 내용은 다음의 라이센스에 따릅니다 :CC Attribution-Noncommercial-Share Alike 3.0 Unported
Recent changes RSS feed Donate Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki