Created
March 30, 2017 20:43
-
-
Save eddieantonio/e17a3e8a093c2e84090a35a9bd2c83d0 to your computer and use it in GitHub Desktop.
Revisions
-
eddieantonio created this gist
Mar 30, 2017 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,19 @@ #!/usr/bin/env python3 # -*- coding: UTF-8 -*- import socket import json server_address = '/tmp/example.sock' sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) sock.connect(server_address) msg = json.dumps({"ping": "hello"}).encode('UTF-8') sock.send(msg) sock.send(b"\r\n") data = sock.recv(256) print(data.decode('UTF-8')) sock.close() This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,29 @@ var net = require('net'); var server = net.createServer(client => { const chunks = []; console.log(`client connected`); client.setEncoding('utf8'); client.on('end', () => { console.log('client disconnected'); }); client.on('data', chunk => { console.log(`Got data: ${chunk}`); chunks.push(chunk) if (chunk.match(/\r\n$/)) { const {ping} = JSON.parse(chunks.join('')); client.write(JSON.stringify({pong: ping})); } }); }); server.on('listening', () => { console.log(`Server listening`); }); server.listen('/tmp/example.sock'); /*eslint no-console: false*/