简体   繁体   English

深流错误侦听EADDRINUSE 127.0.0.1:6020

[英]deepstream error listen EADDRINUSE 127.0.0.1:6020

i try to run my first deepstream.io server from this link but i get this error : 我尝试从此链接运行我的第一个deepstream.io服务器,但出现此错误:

在此处输入图片说明

error: 错误:

CONNECTION_ERROR | Error: listen EADDRINUSE 127.0.0.1:3003
PLUGIN_ERROR | connectionEndpoint wasn't initialised in time
f:\try\deep\node_modules\deepstream.io\src\utils\dependency-
initialiser.js:96
throw error
^

Error: connectionEndpoint wasn't initialised in time
at DependencyInitialiser._onTimeout 
(f:\try\deep\node_modules\deepstream.io\src\utils\dependency-
initialiser.js:94:17)
at ontimeout (timers.js:386:14)
at tryOnTimeout (timers.js:250:5)
at Timer.listOnTimeout (timers.js:214:5)

and this is my code: 这是我的代码:

const DeepStreamServer = require("deepstream.io")
const C = DeepStreamServer.constants;
const server = new DeepStreamServer({
  host:'localhost',
  port:3003
})

server.start();

In deepstream 3.0 we released our HTTP endpoint, by default this runs alongside our websocket endpoint. 在Deepstream 3.0中,我们发布了HTTP终结点,默认情况下,它与websocket终结点一起运行。

Because of this, passing the port option at the root level of the config no longer works (it overrides both the HTTP and websocket port options, as you can see in the screen capture provided, both endpoints are trying to start on the same port). 因此,在配置的根级别传递port选项不再起作用(它覆盖了HTTP和websocket端口选项,正如您在提供的屏幕截图中所看到的那样,两个端点都试图在同一端口上启动) 。

You can override each of these ports as follows: 您可以按如下方式覆盖每个端口:

const deepstream = require('deepstream.io')

const server = new deepstream({
  connectionEndpoints: {
    http: {
      options: {
        port: ...
      }
    },
    websocket: {
      options: {
        port: ...
      }
    }
  }
})
server.start()

Or you can define your config in a file and point to that while initialising deepstream[1]. 或者,您可以在文件中定义配置并在初始化deepstream [1]时指向该配置。

[1] deepstream server configuration [1] 深度服务器配置

All the bellow is for Version 4.2.2 (last version by now) 以下是版本4.2.2(到目前为止的最新版本)

I was having the same Port in use or config file not found errors. 我在使用相同的端口或未找到配置文件错误。 And i was using typescript and i didn't pay attention too to the output dir and build (which can be a problem when one use typescript and build). 而且我正在使用打字稿,但我也没有注意输出目录和构建 (当使用打字稿和构建时可能会出现问题)。 I was able to run the server in the end. 我最终可以运行服务器。 And i had a lot of analysis. 而且我有很多分析。

I checked up the code source and i have seen how the config is loaded 我检查了代码源,并且看到了如何加载配置

const SUPPORTED_EXTENSIONS = ['.yml', '.yaml', '.json', '.js']
const DEFAULT_CONFIG_DIRS = [
  path.join('.', 'conf', 'config'), path.join('..', 'conf', 'config'),
  '/etc/deepstream/config', '/usr/local/etc/deepstream/config',
  '/usr/local/etc/deepstream/conf/config',
]

DEFAULT_CONFIG_DIRS.push(path.join(process.argv[1], '..', 'conf', 'config'))
DEFAULT_CONFIG_DIRS.push(path.join(process.argv[1], '..', '..', 'conf', 'config'))

Also i tested different things and all. 我也测试了不同的东西。 Here what i came up with: 这是我想出的:

  • First of all if we don't precise any parameter in the constructor. 首先,如果我们在构造函数中不精确任何参数。 A config from the default directories will get to load. 默认目录中的配置将被加载。 If there isn't then the server fail to run. 如果没有,则服务器无法运行。 And one of the places where we can put a config is ./conf in the same folder as the server node script. ./conf与服务器节点脚本位于同一文件夹中,是我们可以放置配置的地方之一。

  • Secondly we can precise a config as a string path (parameter in the constructor). 其次,我们可以将配置精确化为字符串路径(构造函数中的参数)。 config.yml or one of the supported extensions. config.yml或受支持的扩展之一。 That will allow the server to load the server config + the permission.yml and users.yml configs. 这将允许服务器加载服务器配置以及permission.yml和users.yml配置。 Which too are supposed to be in the same folder. 哪些也应该位于同一文件夹中。 If not in the same folder there load will fail, and therefor the permission plugin will not load. 如果不在同一文件夹中,则加载将失败,因此权限插件将不会加载。 And so does the users config. 用户配置也是如此。 And no fall back to default will happen. 并且不会退回到默认值。

  • Thirdly the supported extensions for the config files are: yml, yaml, json, js . 第三,配置文件支持的扩展名是: yml,yaml,json,js

  • In nodejs context. 在nodejs上下文中。 If nothing precised. 如果没有严格要求。 There is no fallback to some default config. 没有回退到某些默认配置。 The config need to be provided in one of the default folders, or by precising a path to it. 需要在默认文件夹之一中提供配置,也可以通过指定路径来提供该配置。 Or by passing a config object. 或通过传递配置对象。 And all the optional options will default to some values if not provided ( a bit bellow there is an example that can show that ). 如果未提供,所有可选选项将默认为某些值(下面有一个示例可以显示)。 Know however that precising an end point is very important and required. 但是要知道,确定终点非常重要且必不可少。

  • To precise the path, we need to precise the path to the config.yml file (the server config) [example: path.join(__dirname, './conf/config.yml') ]. 要精确定位路径,我们需要精确定位到config.yml文件(服务器配置)的路径[示例: path.join(__dirname, './conf/config.yml') ]。 Then from the same dir permission.yml and users.yml will be retrieved (the extension can be any of the supported one). 然后从相同的目录Permission.yml和users.yml中检索(扩展名可以是任何受支持的扩展名)。 We can not precise a path to a directory, it will fail. 我们无法精确定位目录的路径,它将失败。

  • We can precise the path to permission config or user config separatly within config.yaml as shown bellow: 我们可以在config.yaml中分别精确设置权限配置或用户配置的路径,如下所示:

# Permissioning example with default values for config-based permissioning
permission:
  type: config
  options:
    path: ./permissions.yml
    maxRuleIterations: 3
    cacheEvacuationInterval: 60000
  • Finally we can pass an object to configure the server, or by passing null as a parameter and use .set methods (i didn't test the second method). 最后,我们可以传递一个对象来配置服务器,或者传递null作为参数并使用.set方法(我没有测试第二种方法)。 For configuring the server we need to follow the same structure as the yml file. 为了配置服务器,我们需要遵循与yml文件相同的结构。 With sometimes a bit different naming. 有时会有一些不同的命名。 The typescript declaration files or types show us the way. 打字稿声明文件或类型向我们展示了方式。 With an editor like vscode. 使用像vscode这样的编辑器。 Even if we are not using typescript we can keep get the auto completion and type definitions. 即使我们不使用打字稿,我们也可以保持自动完成和类型定义。 And the simplest for equivalent to the previous version is : 最简单的等效于以前的版本是:
const webSocketServer = new Deepstream({
    connectionEndpoints: [
        {
            type: 'ws-websocket',
            options: {
                port: 6020,
                host: '127.0.0.1',
                urlPath: '/deepstream'
            }
        }
    ]
});

webSocketServer.start();
  • the above is the new syntax and way. 以上是新的语法和方式。
const server = new DeepStreamServer({
  host:'localhost',
   port:3003
})

^^^^^^^ is completely deprecated and not supported in version 4 (the doc is not updated). 版本4已完全弃用^^^^^^^^,并且版本4不支持(文档未更新)。

One solution that i find is passing empty config object so inseted of : 我发现的一种解决方案是传递这样的空配置对象:

const server = new DeepStreamServer({
  host:'localhost',
   port:3003
})

i'm just using this : 我只是用这个:

 const server = new DeepStreamServer({})

and now everything work's well. 现在一切正常。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM