_ccgi websocket">
当前位置:   article > 正文

C实现WebSocket服务端与订阅端以及HTML5的WebSocket_ccgi websocket

ccgi websocket

WebSocket如何在浏览器端使用

<!DOCTYPE html>
<head>
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0" />
    <meta name="format-detection" content="telephone=no">
    <meta charset="UTF-8">
    <style>
    </style>
</head>
<body>
    <input type="text">
    <button>测试</button>
    <div></div>
</body>
<script>
    var input=document.querySelector('input')
    var button=document.querySelector('button')
    var div=document.querySelector('div')
    //创建websocket对象
    // var socket=new WebSocket('ws://echo.websocket.org')
    var socket=new WebSocket('ws://192.168.32.190:9999')
    //添加连接成功事件监听
    socket.addEventListener('open',()=>{
        div.innerHTML='连接成功'
    })
    socket.addEventListener('message',(msg)=>{
        console.log(msg)
        div.append(msg.data)
    })
    button.addEventListener('click',()=>{
        var value=input.value
        socket.send(value)
        console.log("测试")
    })
</script>
</html>
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35

C实现服务端

源码:
https://github.com/wexiangis/websocket_for_linux
博客参考:
https://blog.csdn.net/SGuniver_22/article/details/74273839?utm_medium=distribute.pc_relevant.none-task-blog-BlogCommendFromBaidu-9.control&depth_1-utm_source=distribute.pc_relevant.none-task-blog-BlogCommendFromBaidu-9.control
抓包参考博客:
https://blog.csdn.net/holandstone/article/details/47026213
select()函数详解:
https://blog.csdn.net/hmxz2nn/article/details/79777372?ops_request_misc=%257B%2522request%255Fid%2522%253A%2522160731167419724839520346%2522%252C%2522scm%2522%253A%252220140713.130102334…%2522%257D&request_id=160731167419724839520346&biz_id=0&utm_medium=distribute.pc_search_result.none-task-blog-2alltop_click~default-1-79777372.nonecase&utm_term=select()&spm=1018.2118.3001.4449

https://blog.csdn.net/lingfengtengfei/article/details/12392449

优秀博客文章:
https://blog.csdn.net/xxdddail/article/details/19070149

http://www.2cto.com/kf/201210/161006.html

TCP协议详解:
https://blog.csdn.net/miao309410364/article/details/50240173

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/很楠不爱3/article/detail/241838
推荐阅读
相关标签
  

闽ICP备14008679号