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. 3D打印GCODE文件学习(二)

    大家可以自己实践一下,那么怎么打开GCODE呢?很简单,只要在桌面上创建一个word文档,然后把“.”后面的docx改成GCODE,它会跳出一个是否更改的框,点击是就行了,然后右键,点击Edit wi ...

  2. Python之路-文件操作(py3)

    文件操作的基本步骤: 1.打开文件:f=open('filename'),with open('filename') as f 2.操作文件:增,删,改,查 3.关闭文件:f.close 打开文件 p ...

  3. Python *Mix_w7

    1. str中的join方法. 把列表转换成字符串 g = ["中国", "美国", "韩国", "法国"] s = & ...

  4. 如何在Linux上清理内存缓存、缓冲与交换空间

    如何在Linux上清理内存缓存.缓冲与交换空间 与其他类型的操作系统一样,GNU/Linux已经有效的实现了内存管理,甚至更加优秀.但是如果任何进程正在吃光你的内存,并且你想清理它,Linux提供了一 ...

  5. 拉格朗日乘子法&KKT条件

    朗日乘子法(Lagrange Multiplier)和KKT(Karush-Kuhn-Tucker)条件是求解约束优化问题的重要方法,在有等式约束时使用拉格朗日乘子法,在有不等约束时使用KKT条件.前 ...

  6. C#实现焦点变色

    Form1.cs using System;using System.Collections.Generic;using System.ComponentModel;using System.Data ...

  7. IDEA控制台乱码解决

    打开Intellij的安装的bin目录(D:\Program Files\JetBrains\IntelliJ IDEA 14.0\bin ),找到上图的两个文件(根据你的系统是32位或64位选择其中 ...

  8. 苹果pns推送和唤醒

    使用的是苹果自己的推送服务器 certificatePath 推送证书 VoipcertificatePath 唤醒证书 certificatePassword 证书密码 以上三项都是需要使用上架了A ...

  9. alpha冲刺(6/10)

    前言 队名:旅法师 作业链接 队长博客 燃尽图 会议 会议照片 会议内容 陈晓彬(组长) 今日进展: 召开会议 撰写博客 召集大家分析了一下后续的问题 问题困扰: 工程量太大,这周考试又很多,周末我让 ...

  10. java中的映射表HashMap、TreeMap

    集(set)是集合(collection),集合不是集. HashMap是散列映射.TreeMap对键进行排序了. map的三个视图:键集.值集合.键/值集. Set<K> keySet( ...