Skip to content

Instantly share code, notes, and snippets.

@robinmonjo
Last active December 20, 2015 23:48
Show Gist options
  • Save robinmonjo/6214729 to your computer and use it in GitHub Desktop.
Save robinmonjo/6214729 to your computer and use it in GitHub Desktop.
tls = require 'tls'
fs = require 'fs'
Connection = require('./connection').Connection
class Rendezvous
@unPairedConnections = []
connectionFindOutSecret: (connection, cb) =>
#check if a connection with the same secret exists in the unPairedConnections list
for co in @unPairedConnections
if co.secret == connection.secret
cb co #telling connection we have found his peer
#remove co and connection from the array they both have met
return
#Launch server
options =
key: fs.readFileSync 'private-key.pem'
cert: fs.readFileSync 'public-cert.pem'
server = tls.createServer options, (socket) ->
#new connection incoming, creating the object and adding it to the list of un paired connection
connection = new Connection socket, this
unPairedConnections.push connection
server.listen 1237, () ->
console.log "Listening on 1237"
module.exports.Rendezvous = Rendezvous
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment