var WebSocketClient = require('websocket').client;

var client = new WebSocketClient();

client.on('connectFailed', function(error) {
console.log('Connect Error: ' + error.toString());
}); client.on('connect', function(connection) {
console.log('WebSocket Client Connected');
connection.on('error', function(error) {
console.log("Connection Error: " + error.toString());
});
connection.on('close', function() {
console.log('echo-protocol Connection Closed');
});
connection.on('message', function(message) {
if (message.type === 'utf8') {
console.log("Received: '" + message.utf8Data + "'");
}
}); function sendNumber() {
if (connection.connected) {
var number = Math.round(Math.random() * 0xFFFFFF);
connection.sendUTF(number.toString());
setTimeout(sendNumber, 1000);
}
}
sendNumber();
}); client.connect('ws://localhost:8080/', 'echo-protocol');

NodeJS client code websocket的更多相关文章

  1. OData Client Code Generator

    转发. [Tutorial & Sample] How to use OData Client Code Generator to generate client-side proxy cla ...

  2. C# Socket TCP Server & Client & nodejs client

    要调试公司某项目里的一个功能,因为要准备测试环境,趁这个机会重温了一下Socket(全还给老师了 -_-#),做个备份. C# Server static void Main(string[] arg ...

  3. What's New In Zeebe: Scaling Zeebe, New Client APIs, Faster Requests, Timestamps, NodeJS Client, and Default Topic is Back!

    Written by Daniel Meyer on May 16 2018 in the What's New In Zeebe category. Welcome to the first-eve ...

  4. [转]OData的初步认识 OData v4 Client Code Generator

    本文转自:http://www.cnblogs.com/1zhk/p/5356053.html What – OData是什么? OData - Open Data Protocol,是一个设计和使用 ...

  5. nodejs——js 实现webSocket 兼容移动端

    nodejs——js 实现webSocket 兼容移动端 //服务器端 //npm install --save ws const express = require('express'); cons ...

  6. presto-gateway nodejs client

    目前已经有了好几个presto nodejs 的client,为了方便presto-gateway 的连接,修改了一个现有的nodejs client 可以方便的连接presto-gateway 原理 ...

  7. golang micro client 报错500 {"id":"go.micro.client","code":408,"detail":"call timeout: context deadline exceeded","status":"Request Timeout"}

    go micro web端连接services时,第一次访问提示500(broken pipe),排查发现客户端请求services时返回 {"id":"go.micro ...

  8. NodeJS反向代理websocket

    如需转载请标明出处:http://blog.csdn.net/itas109QQ技术交流群:129518033 文章目录NodeJS反向代理websocket@[toc]前言代码相关问题:1.http ...

  9. websocket client code html

    <!doctype html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

随机推荐

  1. bzoj1452

    题解: 二位树状数组 然后我开了300*300*300就T了 代码: #include<bits/stdc++.h> using namespace std; ; ],q; int fin ...

  2. web.xml配置以及一些详解

    web.xml的根元素定义如下所示(代表当前使用哪个模版): <?xml version="1.0" encoding="UTF-8"?> < ...

  3. 马凯军201771010116《面向对象程序设计(java)》第六周学习总结

    第一部分:理论知识学习部分 枚举是一种特殊的数据类型,之所以特殊是因为它既是一种类(class)类型却又比类型多了些特殊的约束,但是这些约束的存在也造就了枚举类型的简洁,安全性以及便捷性.创建枚举类型 ...

  4. redis设置过期时间

  5. jQuery-1.样式篇---属性与样式

    jQuery的属性与样式之.attr()与.removeAttr() 每个元素都有一个或者多个特性,这些特性的用途就是给出相应元素或者其内容的附加信息.如:在img元素中,src就是元素的特性,用来标 ...

  6. tcpkill,干掉tcp连接

    场景 当我们需要在不重启服务的情况下断开某一个TCP长连接时,tcpkill工具就非常有用.比如我们要测试某个长连接断开后程序自动重连的情况. tcpkill安装 这个连接的作者改了一下tcpkill ...

  7. Python全栈之路----Python2与Python3

    金角大王Alex  python 之路,致那些年,我们依然没搞明白的编码 python2与python3的区别 py2 str = bytes 为什么有bytes? 是因为要表示图片.视频等二进制格式 ...

  8. 安装ucenter以及单点实现

    1.下载ucenter包 最好是utf-8格式2.解压得到4个安装包 3.1)新建一个站点c 把upload中的所有文件复制到站点根目录下中2)访问出现 Please click here to in ...

  9. CC3000 Arduino 连接Yeelink中文注释 示例

    代码如下“ /*************************************************** *这是一个例子的dfrobot维多-无线集成物联网建兴传感器和控制节点 *产品页面 ...

  10. ios-上传图片到后台

    做第一个项目时,有个版块的个人信息的编辑涉及到头像修改,老大说项目里有通用的代码,让我自己去找.总算找到,搞了许久才弄好,看来理解能力还需要提高啊!! #pragma mark- 修改头像上传后保存 ...