1、下载安装Perl for windows ActivePerl,下载地址:http://www.activestate.com/activeperl/downloads/ ,本文使用ActivePerl-5.10.1.1007-MSWin32-x86-291969.msi,执行安装即可。
2、下载SSL:http://www.openssl.org/source/ ,本文使用openssl-0.9.8l
安装SSL,解压后用文本工具打开INSTALL.W32,根据文档描述的步骤执行(使用“Visual Studio 2008 命令提示”工具执行):
- perl Configure VC-WIN32 --prefix=D:/c++/openssl
- ms/do_ms
- nmake -f ms/ntdll.mak
- nmake -f ms/ntdll.mak test
- nmake -f ms/ntdll.mak install
环境变量中添加 SSL_ROOT = D:/c++/openssl
PATH = %SSL_ROOT%/bin;%SSL_ROOT%/lib
3、ACE+VC2008环境搭建请参见:http://blog.csdn.net/ishow99/archive/2009/11/19/4835161.aspx
4、打开:$(ACE_ROOT)/bin/MakeProjectCreator/config/vc9.features ,设置:ssl=1
5、在$(ACE_ROOT)/bin目录下执行:mpc.pl -type vc9 $(ACE_ROOT)/ace/SSL/ssl.mpc,执行完后,在$(ACE_ROOT)/ace/SSL/目录下将会产生一个Visual Studio的工程文件SSL.vcproj
6、在$(ACE_ROOT)/ace目录下打开ace_vc9.sln文件,然后加入SSL工程文件(SSL.vcproj)即可生成ace_ssl.dll库了
7、转载网络上一段测试代码,实现向www.paypal.com发送GET请求,然后打印服务器返回的内容:
- #include "ace/INET_Addr.h"
- #include "ace/Log_Msg.h"
- #include "ace/Singleton.h"
- #include "ace/Null_Mutex.h"
- #include "ace/SSL/SSL_SOCK_Connector.h"
- #include <ace/SSL/SSl_Sock_Stream.h>
- #ifdef _DEBUG
- #pragma comment(lib, "ACEd.lib")
- #pragma comment(lib, "ACE_SSLd.lib")
- #else
- #pragma comment(lib, "ACE.lib")
- #pragma comment(lib, "ACE_SSL.lib")
- #endif
- #define TEST_GET_BUFFER "GET / HTTP/1.1/r/nHost: www.paypal.com/r/nUser-Agent: TestSSL-Agent0.1/r/n/r/n"
- class Options
- {
- public:
- int oneway_client_test(void);
- void run(void);
- };
- typedef ACE_Singleton<Options, ACE_Null_Mutex> OPTIONS;
- int
- Options::oneway_client_test (void)
- {
- ACE_SSL_SOCK_Stream cli_stream;
- ACE_INET_Addr remote_addr (443, "www.paypal.com");
- ACE_SSL_SOCK_Connector con;
- if (con.connect (cli_stream,
- remote_addr) == -1)
- ACE_ERROR_RETURN ((LM_ERROR,
- ACE_TEXT ("(%P|%t) %p/n"),
- ACE_TEXT ("connection failed")),
- -1);
- else
- ACE_DEBUG ((LM_DEBUG,
- ACE_TEXT ("(%P|%t) connected to %C at port %d/n"),
- remote_addr.get_host_name (),
- remote_addr.get_port_number ()));
- ACE_DEBUG ((LM_DEBUG,
- ACE_TEXT ("(%P|%t) waiting.../n")));
- // send the get request..
- if ( cli_stream.send_n(TEST_GET_BUFFER, ACE_OS::strlen(TEST_GET_BUFFER)) == -1 )
- {
- ACE_ERROR(( LM_ERROR,
- ACE_TEXT("(%P|%t) %p/n)"),
- ACE_TEXT("send_n")));
- cli_stream.close();
- return -1;
- }
- char buf[4096];
- ACE_INT32 len;
- while ( true )
- {
- if ( (len = cli_stream.recv(buf, sizeof(buf) - 1)) == -1 )
- {
- ACE_ERROR(( LM_ERROR,
- ACE_TEXT("(%P|%t) %p/n)"),
- ACE_TEXT("recv_n")));
- break;
- }
- if ( len == 0 )
- break;
- buf[len] = 0;
- ACE_DEBUG(( LM_DEBUG, "%s", buf ));
- }
- // Close the connection.
- cli_stream.close ();
- return 0;
- }
- void
- Options::run (void)
- {
- this->oneway_client_test ();
- }
- static int
- run_client (void)
- {
- OPTIONS::instance ()->run ();
- return 0;
- }
- int
- ACE_TMAIN (int argc, ACE_TCHAR *argv[])
- {
- run_client ();
- return 0;
- }