當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。