如标题所示,建立并连接到服务器时出现错误。我正在使用一个名为simple-websocket的npm库来实现此目的。
在服务器端,我正在使用节点,而对于前端,我正在使用browserify捆绑节点模块。我已经尝试过更改端口,并搜索了没有结果的修复程序。
这是我的节点代码:
const Server = require('simple-websocket/server')
const server = new Server({port: 8181})
new Promise((resolve, reject) => {
server.on('connection', function(socket, request) {
resolve({socket, request})
})
}).then(data => {
console.log(data)
})
这是我的网络代码:
const Socket = require('simple-websocket')
exports.test = function() {
const socket = new Socket('wss://localhost:8181')
socket.on('connect', function() {
console.log('yes')
})
}
这是完整的错误:
WebSocket connection to 'wss://localhost:8181/' failed: Error in connection
establishment: net::ERR_SSL_PROTOCOL_ERROR
bundle.js:6106 Uncaught Error: connection error to wss://localhost:8181
at WebSocket.Socket.self._ws.onerror (bundle.js:6106)
Socket.self._ws.onerror @ bundle.js:6106
error (async)
Socket @ bundle.js:6105
exports.test @ bundle.js:2841
9../middleware-comms/Listen @ bundle.js:2836
o @ bundle.js:1
r @ bundle.js:1
(anonymous) @ bundle.js:1
如果有用,这是浏览器化的代码: http://www.filedropper.com/bundle_2
答案 0 :(得分:1)
您正在创建的function callActivateNewMember(){
LibraryName.activateNewMember()
}
this is the standalone SCRIPT A
function activateNewMember(){
// DECLARE THE CURRENT ACTIVE WORKSHEET as ssCentral
var ssCentral = SpreadsheetApp.openById("xxxxxxxxxxxxxx");
// check if TeamList sheet is active - if not land on Teamlist and ask to select a
new member by his/her first name
// goto and activate TeamList
var teamListSheet = ssCentral.getSheetByName('TEAM LIST');
var teamListSheetIndex = teamListSheet.getIndex()-1;
Logger.log('the teamListSheetIndex is ' + teamListSheetIndex);
var currentSheet = SpreadsheetApp.getActiveSheet().getName();
Logger.log('the currentSheet is ' + currentSheet);
if(currentSheet !='TEAM LIST'){
ssCentral.setActiveSheet(ssCentral.getSheets(
[teamListSheetIndex]).getRange('B5').activate();
Logger.log('WRONG TABLE');
return;
}
var teamListSheetLastRow = teamListSheet.getLastRow();
var nberRows = teamListSheetLastRow-7
// CHECK IF THE CELL IS IN THE FIRST COL AND IS NOT EMPTY
// ------------------get the current row of the member selected
var MemberRow = ssCentral.getCurrentCell().getRow();
var MemberCol = ssCentral.getCurrentCell().getColumn();
if(MemberRow <8 ||MemberCol>1 ){
Logger.log('RIGHT TABLE - WRONG CELL SELECTED');
return;
}
var memberCellValue = ssCentral.getCurrentCell().getValue();
if(memberCellValue=='' ){
Logger.log('CELL SELECTED EMPTY');
return;
}
// VALIDATION : IS THIS MEMBER WAS ALREADY ACTIVATED
//-----------get the column with “Reporting Activated” as header
var repActiveCol = teamListSheet.getRange("D7").getColumn();
//-----------check if the cell of “Reporting Activated” is Y
var checkY = teamListSheet.getRange(MemberRow, repActiveCol).getValue();
//-----------If checkY = “Y” then Alert OK
if (checkY == "Y") {
Logger.log('MEMBER WAS ALREADY ACTIVATED');
return;
}
// rest of the function
}
实例不是在监听加密/ wss / ssl连接,而是在监听标准的websocket连接。您应该尝试使用simple-websocket/server
(而不是ws://localhost:8181
)连接到它。