Skip to content

Instantly share code, notes, and snippets.

@timglabisch
Created September 24, 2012 18:58
Show Gist options
  • Save timglabisch/3777632 to your computer and use it in GitHub Desktop.
Save timglabisch/3777632 to your computer and use it in GitHub Desktop.
server
class Main
constructor: ->
@clients = [];
@tcpServer = new net.createServer();
listen:(@port) ->
@tcpServer.on('connection', (->
client = (new Client).setServer(this);
@clients.push(client);
).bind(this)
);
@tcpServer.listen(@port, (->
console.log('listen on '+@port)
).bind(this) );
class Client
constructor:(@nodeServer) ->
@nodeClient.on('data', (@onData).bind(this));
@nodeClient.on('disconnect', (@onDisconnect).bind(this));
setServer:(@server) ->
onData:(str) ->
@server.send('hi i got ' + str);
onData:(str) ->
@server.send('now i am disconnected!');
prog = (new main).listen(1337)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment