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. C# 中的冒泡排序

    int num; , , , , , , , , , }; ; i < arr.Length; i++) { ; j < arr.Length; j++) { if (arr[j] > ...

  2. Linux防火墙iptables的基础

    一.网络访问控制 1.Linux一般都是作为服务器系统使用,对外提供一些基于网络的服务 2.通常我们都需要对服务器进行一些网络访问控制,类似防火墙的功能 3.常见的访问控制包括:哪些IP可以访问服务器 ...

  3. javaWeb 字体替换过滤器

    字体替换过滤器继承HttpServletRequestWrapper,重定义了: getParameter(),getParameterValues(),getParameterMap(),增强字节替 ...

  4. Saiku更改源代码实现默认查询一天的数据(十)

    Saiku通过更改源代码实现默认查询前一天数据 saiku在本地进行的编译的方式前面已有教程说明,接下来就是更改原代码了 (从网上学得教程,目前只了解到获取最新一天的数据信息) 参考博客地址: htt ...

  5. Nginx源代码安装

    1.确认系统平台及版本 [root@Trial html]# uname -r 2.6.32-696.6.3.el6.x86_64 [root@Trial html]# cat /etc/redhat ...

  6. 测试同学必备抓包工具--charles之mock数据

    charles中有三个是我经常用到来mock数据的. 一. 打断点--Breakpoints 1. 先切换查看‘Structure’模式 2. 找到目标链接,对其父级进行打断点,如图 3. 取消掉再次 ...

  7. Chromium Settings页面修改

    /********************************************************************** * Chromium Settings页面修改 * 说明 ...

  8. idea常用的快捷键

    psvm,快速生存main类 快速生成main类: " public static void main(String[] args) {}",十分常用. 2 sout ,快捷生成输 ...

  9. #考研笔记#计算机之word问题

    Word 问题:1. 如何为文档加密保存?单击 office 按钮\另存为\工具按钮\常规选项\设置打开文件时的密码 2. 怎样在横格稿纸中录入古诗?单击 office 按钮\新建\模板\信纸\稿纸( ...

  10. 从npm 角度理解 mvn 的 pom.xml

    从npm 角度理解 mvn 的 pom.xml pom -- project object model. 用于描述项目的配置: 基础说明 依赖 如何构建运行 类似 node.js 的 package. ...