WebSocket을 통해 브라우저 (예 : browserInstance) 및 Linux 터미널 (ProxyInstance)과 통신 할 수있는 노드 WebServer를 보유하고 있습니다. 웹 서버의 역할은 터미널에서 WebBrowser로 데이터를 넘겨주는 것입니다.노드 서버가 express-ws로 작동하지 않습니다.
var express = require('express');
var expressWs = require('express-ws');
var expressWs = expressWs(express());
var app = expressWs.app;
var appForpage = express();
var browserInstance;
var ProxyInstance;
var browserCounter = 0;
var ProxyCounter = 0;
app.ws('/fromBrowser', function(ws, req, next) {
console.log("~~~~~~~~~~~~BROWSER");
if(browserCounter == 1){
ws.on('message', function(msg) {
console.log("Messagae from Browser :", msg);
ProxyInstance.send(msg);
});
}else{
browserInstance = ws;
ws.on('message', function(msg) {
console.log("Message from Browser :", msg);
ProxyInstance.send(msg);
});
browserCounter = 1;
}
ws.on('close', function(){
console.log("Ws Connection closed");
});
//next();
});
app.ws('/fromProxy', function(ws, req, next) {
console.log("~~~~~~~~~~~~PROXY");
if(ProxyCounter == 0){
ProxyInstance = ws;
ProxyCounter = 1;
}else if(browserCounter == 1){
ws.on('message', function(msg) {
console.log("Message from Proxy: ", msg);
browserInstance.send(msg);
});
}
ws.on('close', function(){
console.log("Ws Connection closed");
});
//next();
});
appForpage.use(express.static(__dirname + '/public/')); // index.html resides in public directory
appForpage.listen(5000)
app.listen(3000)
우선 브라우저 (/ fromBrowser)에서 다음 WS 웹 서버에 프록시의 연결 (/ fromProxy) 등을 만드는 오전 : 아래 server.js 코드를 찾아주세요. 연결이 성공적으로 생성되었습니다. 브라우저에서 웹 서버를 통해 프록시로 데이터를 보내려고하면 잘 동작합니다. WebServer를 통해 브라우저와 통신을 시도 할 때 프록시 끝에서 첫 번째 메시지로 돌아가서이 중 하나가 실패했습니다. 프록시로부터 메시지를받지 못했습니다. 나는 각각의 끝을 같은 순서로 (프록시 먼저 브라우저 다음 ..) 실행해야합니다.
저는 초보자입니다. 내 경우에 인터넷을 통해 예제를 찾지 못했습니다. 내가 여기서 무엇을 놓치고 있니?
.I 프록시에서 내 님에게 메일 콜백을 등록하지 않은 :(정말 바보