当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript zmq.socket函数代码示例

本文整理汇总了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;未经允许,请勿转载。