Skip to content

Instantly share code, notes, and snippets.

@changtimwu
Created April 8, 2013 03:29
Show Gist options
  • Select an option

  • Save changtimwu/5334054 to your computer and use it in GitHub Desktop.

Select an option

Save changtimwu/5334054 to your computer and use it in GitHub Desktop.
# yon can connect to server with the following command
# socat -,raw,echo=0,escape=0x0f UNIX-CONNECT:/tmp/echo.socket
net = require('net')
readline = require('readline')
create_cli_session = (sr)->
rl = readline.createInterface sr, sr
rl.setPrompt('OHAI> ')
rl.prompt()
rl.on 'line', (line) ->
switch line.trim()
when 'taipei'
sr.write 'tainan\r\n'
when 'hello'
sr.write 'world\r\n'
when 'close'
rl.close()
else
sr.write ('Say what? I might have heard `' + line.trim() + '`')
rl.prompt()
rl.on 'close', ->
console.log('client quit')
server = net.createServer (c)->
console.log('server connected')
c.on 'end', ->
console.log 'server disconnected'
c.isTTY = true
create_cli_session c
server.listen '/tmp/echo.socket', ->
console.log('server bound')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment