Windows下编译websocketpp

14 篇文章 0 订阅
11 篇文章 0 订阅

系统环境是win7 64位,安装了vs2008

准备工作

1.到https://github.com/zaphoyd/websocketpp/tags下载websocketpp最新稳定版0.6.0

2.到https://sourceforge.net/projects/boost/files/boost/1.62.0/下载boost最新版本1.62.0

3.到http://download.csdn.net/detail/huanggang982/9698627下载ActivePerl_5.16.2.3010812913.msi

4.到http://www.nasm.us/pub/nasm/releasebuilds/2.12/下载nasm-2.12-installer-x86.exe

4.到https://github.com/openssl/openssl/releases下载openssl1.1.0版本

第一步:安装ActicePerl,直接下一步,然后配置环境变量,在系统变量path中增加“D:\Perl\bin”

第二步:安装nasm,配置环境变量,在系统变量path中增加“C:\Program Files (x86)\nasm”

第三步:编译openssl

按照openssl 根目录 INSTALL 介绍了编绎过程:

“ on Windows (only pick one of the targets for configuration):


    $ perl Configure { VC-WIN32 | VC-WIN64A | VC-WIN64I | VC-CE }
    $ nmake
    $ nmake test
    $ nmake install


1.打开vs2010 tool cmd x86环境  // vcvarsall x86
2.cd x:\openssl-OpenSSL_1_1_0

3.perl Configure VC-WIN32 --prefix=d:/openssl-install

4.nmake

5.nmake install

配置VS2008

    选择“Tools”(工具)->“Options”(选项)->“Projects and solutions”(项目和解决方案)->“VC ++ directories”(VC++目录)。

     配置Include包含文件)目录,增加D:\openssl-install\bin\v9\include\boost-1_62

    配置Library库文件)目录,增加D:\openssl-install\bin\v9\lib


第四步:编译boost

0.解压boost_1_62_0.7z

1.打开VS2008,选择“Tools”(工具)->“Visual Studio 2008 command prompt”(命令提示),进入命令行界面。

2.进入到“D:\Program\open\boost_1_62_0”,执行“bootstrap.bat”进行引导。

3.引导成功之后在相同目录下会生成bjam.exe。执行如下命令进行编译:

     bjam install architecture=x86 address-model=32 --toolset=msvc-9.0 --without-python --build-type=complete --prefix="D:\boost_1_62_0\bin\v9" link=static runtime-link=shared threading=multi debug release

  

配置VS2008

    选择“Tools”(工具)->“Options”(选项)->“Projects and solutions”(项目和解决方案)->“VC ++ directories”(VC++目录)。

     配置Include包含文件)目录,增加D:\boost_1_62_0\bin\v9\include\boost-1_62

    配置Library库文件)目录,增加D:\boost_1_62_0\bin\v9\lib

参考:http://www.cnblogs.com/helloamigo/p/3572577.html

第五步:测试

新建一个win32控制台空项目,把websocketpp-0.6.0\examples\print_server下面的print_server.cpp加入到工程中,编译通过,运行起来。

新建test.html文件加入如下内容:

<!DOCTYPE html>    
<html>    
<head>    
<meta charset="UTF-8">  
</head>    
<body>    
    <div>    
        <input type="submit" value="Start" οnclick="start()" />    
    </div>    
    <div id="messages"></div>    
    <script type="text/javascript">    
        //var webSocket =  new WebSocket('ws://localhost:8080/testWebSocketProtocol/websocket');  
        var webSocket =  new WebSocket('ws://localhost:9002');  
    
        webSocket.onerror = function(event) {    
            onError(event)    
        };    
    
        webSocket.onopen = function(event) {    
            onOpen(event)    
        };    
    
        webSocket.onmessage = function(event) {    
            onMessage(event)    
        };    
    
        function onMessage(event) {    
            document.getElementById('messages').innerHTML     
                += '<br />Get Message From Server: ' + event.data;    
        }    
    
        function onOpen(event) {    
            document.getElementById('messages').innerHTML     
                = 'Connection established';    
        }    
    
        function onError(event) {    
            alert(event.data);    
            alert("error");    
        }    
    
        function start() {    
            webSocket.send('hello');    
            return false;    
        }    
    </script>    
</body>    
</html>    


用浏览器打开网页,网页上打印"Connection established",再点击start按钮接着显示"Get Message From Server:hello"

服务器打印


通信正常。
  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值