Commit 6b407180 authored by Luc Didry's avatar Luc Didry
Browse files

Make server listening on socket

parent f58cb30f
Pipeline #23891 passed with stage
in 24 seconds
const http = require('http');
const port = 3000;
var url = require('url');
var Canvas = require('canvas')
var fs = require('fs');
var net = require('net');
const requestHandler = (request, response) => {
var queryData = url.parse(request.url, true).query;
......@@ -66,12 +67,32 @@ const requestHandler = (request, response) => {
const server = http.createServer(requestHandler)
server.listen(port, (err) => {
server.listen('/tmp/wemawema.sock', (err) => {
if (err) {
return console.log('something bad happened', err)
return console.log('something bad happened', err);
} else {
console.log('server is listening on socket /tmp/wemawema.sock');
}
});
console.log(`server is listening on ${port}`)
server.on('error', function (e) {
if (e.code == 'EADDRINUSE') {
var clientSocket = new net.Socket();
clientSocket.on('error', function(e) { // handle error trying to talk to server
if (e.code == 'ECONNREFUSED') { // No other server listening
fs.unlinkSync('/tmp/wemawema.sock');
server.listen('/tmp/wemawema.sock', (err) => {
if (err) {
return console.log('something bad happened', err)
}
});
}
});
clientSocket.connect({path: '/tmp/wemawema.sock'}, function() {
console.log('Server running, giving up...');
process.exit();
});
}
});
function roundRect(ctx, x, y, width, height, radius, fill, stroke) {
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment