<template>
<div>
<el-button @click="clear()">清空</el-button>
<el-button @click="close()">关闭</el-button>
<el-button @click="start()">启动</el-button>
<el-button @click="send()">发送</el-button>
<div class="widget-body" style="height: 500px;">
<el-form ref="form3" :model="form3" label-width="0px">
<el-form-item label="" style="height: 90px;">
<el-input type="textarea" v-model="form3.remark" :rows="20"
placeholder="json"></el-input>
</el-form-item>
</el-form>
</div>
</div>
</template>
<script>
export default {
data() {
return {
websock: null,
form3: {
remark: ''
}
}
},
created() {
// this.websock = new WebSocket('ws://192.168.122.136:5414')
// this.form3.remark = this.form3.remark + '连接状态:' + this.websock.readyState + ' \r\n'
// this.websock.onopen = this.websocketonopen
// this.websock.onmessage = this.websocketonmessage
// this.websock.onerror = this.websocketerror
// this.websock.onclose = this.websocketclose
},
methods: {
clear() {
this.form3.remark = ''
},
close() {
},
start() {
// 需判断不重复启动,启动一次,启动多次会收到多条返回值 192.168.122.136 127.0.0.1
this.websock = new WebSocket('ws://192.168.122.136:5414')
this.form3.remark = this.form3.remark + '连接状态:' + this.websock.readyState + ' \r\n'
this.websock.onopen = this.websocketonopen
this.websock.onmessage = this.websocketonmessage
this.websock.onerror = this.websocketerror
this.websock.onclose = this.websocketclose
},
send() {
let actions = {'hardwaretype':'0','modeltype':'1000','opercode': 'zhangc','opername': 'zc测试','servicecode': 'routerurl','serviceinfo':{'infos':'hello'}}
this.form3.remark = this.form3.remark + '发送json:' + JSON.stringify(actions) + ' \r\n'
this.websocketsend(JSON.stringify(actions))
},
// 连接建立之后执行send方法发送数据
websocketonopen() {
this.form3.remark = this.form3.remark + 'open' + ' \r\n'
// let actions = {'reqtype': '1001'}
// this.form3.remark = this.form3.remark + '发送json:' + JSON.stringify(actions) + ' \r\n'
// this.websocketsend(JSON.stringify(actions))
},
// 数据发送
websocketsend(agentData) {
this.websock.send(agentData)
// this.form3.remark = this.form3.remark + '发送\r\n '
},
// 数据接收
websocketonmessage(e) {
const redata = JSON.parse(e.data)
this.form3.remark = this.form3.remark + '接收json:' + JSON.stringify(redata) + ' \r\n'
},
websocketerror(e) {
this.form3.remark = this.form3.remark + 'error\r\n '
},
websocketclose(e) {
this.form3.remark = this.form3.remark + 'connection closed (' + e.code + ')\r\n '
}
}
}
</script>
没有合适的资源?快使用搜索试试~ 我知道了~
c#websocket服务与vue通讯
共2个文件
cs:1个
vue:1个
需积分: 50 66 下载量 122 浏览量
2018-11-28
13:21:40
上传
评论
收藏 3KB ZIP 举报
温馨提示
代替ocx、ppapi、npapi等通过web页面访问本地资源的插件方式,页面需支持HTML5。使用c#编写websocket服务端,使用vue编写的客户端,在一台电脑上实现vue发起访问指令,通过websocket协议访问本机websocket服务,服务端接收到指令后开发访问本地资源。不明白的地方加qq286194946
资源推荐
资源详情
资源评论
收起资源包目录
c#websocket服务与vue通讯.zip (2个子文件)
websocket 通讯服务端源码文件.cs 8KB
websocket js.vue 3KB
共 2 条
- 1
资源评论
编码15年
- 粉丝: 1
- 资源: 4
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功