Skip to content

Commit

Permalink
sdk/js: reimplemented reconnection logic
Browse files Browse the repository at this point in the history
  • Loading branch information
lithdew committed Jun 12, 2020
1 parent cafa9f3 commit ae8b1ce
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions ts/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,22 @@ async function main() {

await client.start({port: 9000, host: "127.0.0.1"});

client.conn.on('close', () => {
const reconnect = async () => {
console.log(`Trying to reconnect to ${ip.toString(client.id.host, 12, 4)}:${client.id.port}. Sleeping for 1s.`);

try {
await client.start({port: 9000, host: "127.0.0.1"});

console.log(`Successfully connected to ${ip.toString(client.id.host, 12, 4)}:${client.id.port}.`);
} catch (err) {
setTimeout(reconnect, 1000);
}
};

setTimeout(reconnect, 1000);
})

console.log(`Successfully connected to ${ip.toString(client.id.host, 12, 4)}:${client.id.port}.`);
}

Expand Down

0 comments on commit ae8b1ce

Please sign in to comment.