The Pursuit of Happyness

반응형

윈도우에서 npm으로 oracledb 모듈을 설치하던 중에 다음과 같은 에러가 발생했습니다.


MSBUILD : error MSB4132: The tools version "2.0" is unrecognized. Available tools versions are "4.0".


모듈 설치를 위해서 Python 2.7 과 Visual Studio 2017 CE 를 설치해 두었는데, 위와 같은 에러가 발생했습니다.


(참고로 node oracledb를 설치하기 위해서는 Oracle Instant Client 혹은 XE 등이 필요하고, 그 외에 Python 과 C++ 컴파일러가 필요합니다.)



관련해서 검색을 하다가 아래 링크에서 답을 찾았습니다.


https://github.com/chjj/pty.js/issues/60



요점만 적어보면, 


1. 관리자 권한으로 명령 프롬프트를 실행합니다.


2. 다음 명령으로 빌드 관련 툴을 설치합니다.


 npm install --global --production windows-build-tools 


3. 다음 명령으로 빌드 툴에서 사용할 visual studio 버전을 설정합니다.


 npm config set msvs_version 2015 --global


그리고 나서 창을 닫고 새 창을 열어서 다시 시도하니 설치가 잘 되었습니다.







반응형

반응형

실행환경 Ubuntu 14.04 LTS / node v0.10.25


이번에는 events 모듈을 이용한 채팅서버 코드이다.

events 모듈을 이용하여 원하는 명령어에 대한 동작을 다음과 같이 구현하면 된다.

event를 전송하는 channel 객체를 생성하고, 채널 객체에 clients 에는 소켓들을, subscriptions 에는 각 클라이언트에 전달하는 메써드를 지정한다.

클라이언트 연결시에는 'join' 이벤트가, 연결 종료시에는 'leave' 이벤트가 처리된다.


var events = require('events');
var net = require('net');

var channel = new events.EventEmitter();
channel.clients = {};
channel.subscriptions = {};

channel.on('join',
        function(id, client) {
                this.clients[id] = client;
                this.subscriptions[id] = function(senderId, message) {
                        if (id != senderId) {
                                this.clients[id].write(message);
                        }
                }
                this.on('broadcast', this.subscriptions[id]);
        }
);

channel.on('leave',
        function(id) {
                channel.removeListener('broadcast', this.subscriptions[id]);
                channel.emit('broadcast', id, id + " has left the chat.\n");
        }
);

var server = net.createServer(
        function(client) {
                var id = client.remoteAddress + ':' + client.remotePort;
                channel.emit('join', id, client);
                client.on('data',
                        function(data) {
                                channel.emit('broadcast', id, data.toString());
                        }
                );
                client.on('close',
                        function() {
                                channel.emit('leave', id);
                        }
                );
        }
);
server.listen(3000);


반응형