<commit_before>'use strict'
var pick = require('lodash.pick')
var createServer = require('pull-ws/server')
var http = require('http')
var util = require('../util')

module.exports = function listen(params) {
  if (params) params = pick(params, 'host', 'port', 'path', 'protocol')
 var notify = util.createNotify()
  var _server=http.createServer(function (req, res) {
      res.end(params.port || '')
    })
  var server = createServer({
    server:_server
  }, function (c) {
    c.type = 'connection'
    notify(c)
  })
  .listen(params, function () { notify({ type: 'ready' ,port:_server.address().port}) })

  var source = notify.listen()

  source.protocol = params.protocol || 'ws:'

  source.end = function (err) {
    server.close(function () {
      notify.end(err)
    })
  }

  return source
}<commit_msg>Fix for ws listen wrong address on ready event<commit_after>'use strict'
var pick = require('lodash.pick')
var createServer = require('pull-ws/server')
var http = require('http')
var util = require('../util')

module.exports = function listen(params) {
  if (params) params = pick(params, 'host', 'port', 'path', 'protocol')
  var notify = util.createNotify()
  var _server=http.createServer(function (req, res) {
      res.end(params.port || '')
    })
  var server = createServer({
    server:_server
  }, function (c) {
    c.type = 'connection'
    notify(c)
  })
  .listen(params, function () { 
    notify({ type: 'ready' ,address: _server.address().address,port:_server.address().port}) 
  })

  var source = notify.listen()

  source.protocol = params.protocol || 'ws:'

  source.end = function (err) {
    server.close(function () {
      notify.end(err)
    })
  }

  return source
}
{'fraction_non_alphanumeric': 0.16851960210649503, 'fraction_numerical': 0.0, 'mean_word_length': 3.6091644204851754, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1253927', 'n_tokens_mistral': 550, 'n_tokens_neox': 535, 'n_words': 131}