• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

TypeScript zmq.socket函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了TypeScript中zmq.socket函数的典型用法代码示例。如果您正苦于以下问题:TypeScript socket函数的具体用法?TypeScript socket怎么用?TypeScript socket使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了socket函数的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的TypeScript代码示例。

示例1: setInterval

var playGame = (gameData) => {
    var id:string = gameData.name;
    console.log(id + " is starting to reek havoc");

    var controlSocket = zmq.socket('push');
    controlSocket.connect('tcp://' + server + ':' + control_port);
    // These chaos monkeys don't even need to watch the state socket

    var step = () => {
        var f = 1,
            r = 0;

        controlSocket.send(gameData.secret + "," + f + "," + r);

        if (gameNotOver) {
            setInterval(step, UPDATE_RATE);
        }
    };
    step()
};
开发者ID:adelescott,项目名称:spacerace,代码行数:20,代码来源:chaos-race.ts


示例2: connect

export function connect() {
    var requester = zmq.socket('req');

    var x = 0;
    requester.on("message", (reply) => {
        console.log("Received reply", x, ": [", reply.toString(), ']');
        if (x === 10) {
            requester.close();
        }
    })

    requester.connect("tcp://localhost:5555");

    for (var i = 0; i < 10; i++) {
        console.log("Sending request", i, '…');
        requester.send("Hello");
    }

    process.on('SIGINT', function() {
        requester.close();
    });

}
开发者ID:Ao21,项目名称:vsc-robotframework-server,代码行数:23,代码来源:index.ts


示例3: function

// Websocket component
io.on('connection', function(ws){
    console.log('A websocket connected');

    ws.on('disconnect', function(){
        console.log('Websocket disconnected');
    });

});


// ZMQ component
console.log('Frontend is trying to connect to ' + server);

var lobbySocket = zmq.socket('req');
var logSocket = zmq.socket('sub');
var gameStateSocket = zmq.socket('sub');


//lobbySocket.subscribe("");
logSocket.subscribe("");

gameStateSocket.subscribe("");

// On receiving a message from the game server
// Note the `msg` is a string or buffer, not JSON
lobbySocket.on('message', function(msg){
    console.log('[LOBBY] Received: %s', msg.toString());
});
开发者ID:adelescott,项目名称:spacerace,代码行数:29,代码来源:server.ts


示例4:

/// <reference path="../../typings/tsd.d.ts" />
"use strict";
import * as fs from 'fs';
import * as zmq from 'zmq';

// Create publisher endpoint
let publisher = zmq.socket('pub');
let filename = process.argv[2];

fs.watch(filename, () => {
	// send the message to any subscribers
	publisher.send(JSON.stringify({
		type: 'changed',
		file: filename,
		timestamp: Date.now()
	}));
});

publisher.bind('tcp://*:5444', (err) => {
	if(err) { throw err; }
	console.log('Listening for ZMQ subscribers');
});
开发者ID:dam,项目名称:explore_web_frameworks,代码行数:22,代码来源:zmq-publisher.ts


示例5: require

var zmq = require('zmq');


var UPDATE_RATE = 30; // [ms]
var NUM_SHIPS = parseInt(process.argv.length > 2 ? process.argv[2] : '10');
var server = process.argv.length > 3 ? process.argv[3] : 'localhost';

var state_port = 5556;
var control_port = 5557;
var lobby_port = 5558;

// Share one state socket
var latestState;
var gameNotOver = true;
var stateSocket = zmq.socket('sub');
var lobbySocket = zmq.socket('req');

console.log("Connecting to lobby");
lobbySocket.connect('tcp://' + server + ':' + lobby_port);
lobbySocket.on('message', (msg) => {
    var data = JSON.parse(msg);
    console.log("LOBBY: ", data);
    playGame(data);
});


stateSocket.subscribe('');
stateSocket.on('message', function(topic, msg) {
    console.log('[GAME] Received State for: %s', topic.toString());
    latestState = JSON.parse(msg.toString());
开发者ID:adelescott,项目名称:spacerace,代码行数:30,代码来源:chaos-race.ts


示例6: Date

/// <reference path="../../typings/tsd.d.ts" />
"use strict";
import * as zmq from 'zmq';

interface Message {
	type: string
	file: string
	timestamp: number
}

let subscriber = zmq.socket('sub');
subscriber.subscribe(''); // subscribe to all the messages

subscriber.on('message', (data) => {
	let message: Message = JSON.parse(data.toString());
	let {type, file, timestamp} = message;
	let date = new Date(timestamp);
	console.log(`File ${file} changed at ${date}`);
})

subscriber.connect('tcp://localhost:5444');
开发者ID:dam,项目名称:explore_web_frameworks,代码行数:21,代码来源:zmq-subscriber.ts



注:本文中的zmq.socket函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
TypeScript cache.InfrastructureCaches类代码示例发布时间:2022-05-24
下一篇:
TypeScript zlib.inflateSync函数代码示例发布时间:2022-05-25
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap