Skip to content

Commit

Permalink
! fix websocket
Browse files Browse the repository at this point in the history
  • Loading branch information
grrrisu committed Mar 30, 2016
1 parent 1f1198e commit 53b5ba1
Showing 1 changed file with 16 additions and 16 deletions.
32 changes: 16 additions & 16 deletions node/lib/web_socket.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,21 @@
const retry = require('retry');
const unix_socket = require('./unix_socket');

const connect_to_unix_socket = function(socket_file, callback){
let operation = retry.operation();
operation.attempt(function(currentAttempt){
unix_socket.connect(socket_file, (err, socket) => {
if(operation.retry(err)){
client.emit("net-status", {message: "sim server is not available", key: "server_away", error: err});
return;
} else {
callback(socket);
}
});

});
};

exports.connect = function(server, socket_file){

const io = require('socket.io')(server);
Expand All @@ -17,7 +32,7 @@ exports.connect = function(server, socket_file){
console.log(id + " : " + token + " joined");
player_id = id;

connect_unix_socket(socket_file, (socket) => {
connect_to_unix_socket(socket_file, (socket) => {
serverConnection = socket;
serverConnection.browserConnection = client;
client.emit("net-status", {message: "connected to sim server", key: "server_connected", error: null});
Expand All @@ -43,18 +58,3 @@ exports.connect = function(server, socket_file){
});

};

connect_to_unix_socket(socket_file, callback){
let operation = retry.operation();
operation.attempt(function(currentAttempt){
unix_socket.connect(socket_file, (err, socket) => {
if(operation.retry(err)){
client.emit("net-status", {message: "sim server is not available", key: "server_away", error: err});
return;
} else {
callback(socket);
}
});

});
}

0 comments on commit 53b5ba1

Please sign in to comment.