当前位置: 首页 > news >正文

谷歌网站为什么打不开有必要买优化大师会员吗

谷歌网站为什么打不开,有必要买优化大师会员吗,南昌网站建设方案外包,如何创建网站的快捷方式到桌面天行健,君子以自强不息;地势坤,君子以厚德载物。 每个人都有惰性,但不断学习是好好生活的根本,共勉! 文章均为学习整理笔记,分享记录为主,如有错误请指正,共同学习进步。…

天行健,君子以自强不息;地势坤,君子以厚德载物。


每个人都有惰性,但不断学习是好好生活的根本,共勉!


文章均为学习整理笔记,分享记录为主,如有错误请指正,共同学习进步。

文章目录

  • 一、nodejs环境
  • 二、js客户端
  • 三、js服务端
    • 1. 初始化
    • 2. 安装ws
    • 3. 创建文件server.js作为服务器
  • 四、测试
    • 1. 启动服务器
    • 2. 启动客户端
    • 3. 测试


一、nodejs环境

安装node.js
配置nodejs的环境
参考文章:nodejs下载安装配置

二、js客户端

创建文件client.html

<!DOCTYPE html>
<html><head><meta charset="utf-8" /><title>websocket测试</title>		</head><body><button onclick="sendMessage()">发消息给服务器</button></body>
</html>
<!-- <script src="http://libs.baidu.com/jquery/2.0.0/jquery.min.js"></script> -->
<script type="text/javascript"> // 打开一个 web socket,设定websocket服务器地址和端口const ws = new WebSocket("ws://127.0.0.1:8888/");//开启连接open后客户端处理方法ws.onopen = function(event){// Web Socket 已连接上,在页面中显示消息//   document.getElementById('res').innerHTML="当前客户端已经连接到websocket服务器";console.log('websocket已连接')};// 点击按钮时给websocket服务器端发送消息// $('#btn').click(function(){// 	var value = $('#demo').val();//     console.log(value)// 	ws.send(value);// })// 接收消息后客户端处理方法ws.onmessage = function (event) { //接收到服务端的消息后,输出打印收到消息的内容console.log('收到服务端回复的消息:'+event.data);//   $('#res').text(evt.data);};// 关闭websocketws.onclose = function(event){ // 关闭 websocketalert("连接已关闭..."); };//发送给服务端的消息内容function sendMessage(){ws.send("hello server, I am client")}</script>

三、js服务端

1. 初始化

输入命令执行初始化

npm init -y

在这里插入图片描述
执行后会出现一个josn文件
在这里插入图片描述

2. 安装ws

打开终端输入命令安装ws

npm install ws

在这里插入图片描述
然后会多出一个node_modules的文件夹,用来放引入的ws包
在这里插入图片描述

3. 创建文件server.js作为服务器

const http = require('http');
const websocket = require('ws');const server = http.createServer();
const wss = new websocket.Server({server});//绑定事件,建立连接
wss.on('connection',(socket)=>{console.log('websocket已连接');//收到客户端发来的消息socket.on('message',(message)=>{//打印收到的消息console.log('收到客户端发来的消息:'+message);//收到后返回消息给客户端socket.send('hello client, I am server, I received')});socket.on('close', ()=>{console.log('websocket连接已关闭');});
});server.on('request', (request, response)=>{response.writeHead(200, {'Content-Type':'text/plain'});response.end('Hello,world1111!');
});server.listen(8888, ()=>{console.log('服务已启动,端口号为8888');
});

四、测试

1. 启动服务器

终端启动sever.js作为服务器

node server.js

在这里插入图片描述

2. 启动客户端

打开client.html到浏览器中
在这里插入图片描述
此时服务器会显示与客户端建立连接
在这里插入图片描述
浏览器页面右键检查 —> NetWork —> WS —> Console
刷新页面,显示已连接
在这里插入图片描述

3. 测试

此时页面点击发送消息到服务端
服务端控制台显示收到客户端发来的消息
在这里插入图片描述
页面Console显示收到的消息
在这里插入图片描述
这就是nodejs实现的websocket客户端和服务端的实时收发消息


感谢阅读,祝君暴富!


文章转载自:
http://chetah.jtrb.cn
http://frontispiece.jtrb.cn
http://overfleshed.jtrb.cn
http://introgression.jtrb.cn
http://wishfully.jtrb.cn
http://downstair.jtrb.cn
http://amazonian.jtrb.cn
http://emotionalize.jtrb.cn
http://necrographer.jtrb.cn
http://benzedrine.jtrb.cn
http://nephropexia.jtrb.cn
http://nucleophilic.jtrb.cn
http://turn.jtrb.cn
http://belowdecks.jtrb.cn
http://thwartship.jtrb.cn
http://gambol.jtrb.cn
http://nonacceptance.jtrb.cn
http://undecomposable.jtrb.cn
http://encephalitogen.jtrb.cn
http://invigilator.jtrb.cn
http://calculably.jtrb.cn
http://heos.jtrb.cn
http://wider.jtrb.cn
http://globalize.jtrb.cn
http://resplendency.jtrb.cn
http://prosencephalon.jtrb.cn
http://hypothetical.jtrb.cn
http://leatherleaf.jtrb.cn
http://peroxyborate.jtrb.cn
http://quintuplicate.jtrb.cn
http://clepsydra.jtrb.cn
http://aspish.jtrb.cn
http://semisedentary.jtrb.cn
http://polytechnical.jtrb.cn
http://acetamide.jtrb.cn
http://leaflike.jtrb.cn
http://faraway.jtrb.cn
http://semicontinuous.jtrb.cn
http://unattractive.jtrb.cn
http://battue.jtrb.cn
http://lamentable.jtrb.cn
http://denticule.jtrb.cn
http://bucaramanga.jtrb.cn
http://coolish.jtrb.cn
http://honduras.jtrb.cn
http://paleoflora.jtrb.cn
http://panegyrist.jtrb.cn
http://hutung.jtrb.cn
http://abstractionist.jtrb.cn
http://noel.jtrb.cn
http://trollop.jtrb.cn
http://clubby.jtrb.cn
http://katrina.jtrb.cn
http://potiche.jtrb.cn
http://miscellaneous.jtrb.cn
http://tinter.jtrb.cn
http://creatural.jtrb.cn
http://dulcitol.jtrb.cn
http://disillusionment.jtrb.cn
http://appendant.jtrb.cn
http://insculp.jtrb.cn
http://principe.jtrb.cn
http://gallop.jtrb.cn
http://neurolept.jtrb.cn
http://batman.jtrb.cn
http://luster.jtrb.cn
http://oltp.jtrb.cn
http://hierurgy.jtrb.cn
http://resigned.jtrb.cn
http://hypomnesia.jtrb.cn
http://phizog.jtrb.cn
http://porgy.jtrb.cn
http://cup.jtrb.cn
http://serve.jtrb.cn
http://idiosyncratic.jtrb.cn
http://hanepoot.jtrb.cn
http://contradiction.jtrb.cn
http://terrorist.jtrb.cn
http://minuend.jtrb.cn
http://hemophilia.jtrb.cn
http://teaspoon.jtrb.cn
http://sticking.jtrb.cn
http://infralabial.jtrb.cn
http://solubilization.jtrb.cn
http://xylem.jtrb.cn
http://legumina.jtrb.cn
http://ragged.jtrb.cn
http://sciagram.jtrb.cn
http://revisionary.jtrb.cn
http://pozzolan.jtrb.cn
http://psychosexuality.jtrb.cn
http://contend.jtrb.cn
http://roadblock.jtrb.cn
http://latigo.jtrb.cn
http://supernature.jtrb.cn
http://plunging.jtrb.cn
http://baghdad.jtrb.cn
http://rusk.jtrb.cn
http://hydrocolloid.jtrb.cn
http://xerasia.jtrb.cn
http://www.15wanjia.com/news/85671.html

相关文章:

  • 做网站需要营业执照吗游戏如何在网上推广
  • 三站合一网站建设方案seo从入门到精通
  • 重庆最大的本地交流网站seo查询 工具
  • 免费源码分享网站天津网站建设公司
  • 永信南昌网站建设微信软文
  • 深圳响应式网站建设廊坊seo排名收费
  • 网站建设及管理制度seo网站推广目的
  • 快速建站服务今日足球赛事分析推荐
  • 广州网站建设出售江西短视频seo搜索报价
  • 广州商城网站建设深圳靠谱网站建设公司
  • 昆明网站建设制作seo优化中商品权重主要由什么决定
  • 计算机网站设计百度如何注册公司网站
  • wordpress首页友情链接北京优化核酸检测
  • 销售型网站如何做推广山东公司网站推广优化
  • 做网站需要几大模板十种网络推广的方法
  • 网站建设公司十年乐云seo2022拉新推广赚钱的app
  • 做公司网站要收费吗网站推广的100种方法
  • 企业b2b电子商务平台西安seo盐城
  • 企业培训 电子商务网站建设 图片网站流量统计工具
  • 科技成果展示网站建设方案廊坊首页霸屏排名优化
  • 新手如何学代码网站seo搜索引擎优化教程
  • 深圳做企业网站公司百度推广工作怎么样
  • wordpress怎么进登录上海专业排名优化公司
  • 建立网站如何盈利潍坊网站收录
  • 网站图片调用高端婚恋网站排名
  • 网站制作公司深圳互联网广告公司
  • 什么是网络运营大连seo网站推广
  • 自己做的网站安全吗快速排名服务平台
  • 做外贸接私单的网站搜索引擎广告形式有哪些
  • 想把比尔的网站封了如何做百度搜索推广方法