NodeJS, 포트에서 서버를 실행할 수 없음 : 수신 EADDRINUSE : 이미 사용중인 주소 ::: 3001,하지만 사용되지 않는 포트, Socket.io

noober1

socket.io 서버를 실행하려고하는데 포트 3001이 사용되고 있다는 뜻입니다. 다른 포트 3000에서 다른 스크립트로 익스프레스 서버를 실행하면 정상적으로 실행되지만이 특정 스크립트에서는 3000도 사용 중이라는 메시지가 표시되기 때문에 이상하게 느껴집니다 (다른 많은 포트를 시도했지만 작동하지 않는 것 같습니다. 그들 모두). 이 두 포트가 내 웹 서버에서 사용되지 않는다는 것을 알고 있으며 아무것도 실행하지 않아서 이상하다고 생각합니다.

콘솔 오류 :

[root@server:LifeNet_Temp]$ npm run test

> [email protected] test /home/main/public_html/LifeNet_Temp
> node server.js

events.js:288
      throw er; // Unhandled 'error' event
      ^

Error: listen EADDRINUSE: address already in use :::3001
    at Server.setupListenHandle [as _listen2] (net.js:1309:16)
    at listenInCluster (net.js:1357:12)
    at Server.listen (net.js:1445:7)
    at Object.<anonymous> (/home/main/public_html/LifeNet_Temp/server.js:34:8)
    at Module._compile (internal/modules/cjs/loader.js:1158:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1178:10)
    at Module.load (internal/modules/cjs/loader.js:1002:32)
    at Function.Module._load (internal/modules/cjs/loader.js:901:14)
    at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:74:12)
    at internal/main/run_main_module.js:18:47
Emitted 'error' event on Server instance at:
    at emitErrorNT (net.js:1336:8)
    at processTicksAndRejections (internal/process/task_queues.js:84:21) {
  code: 'EADDRINUSE',
  errno: 'EADDRINUSE',
  syscall: 'listen',
  address: '::',
  port: 3001
}
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] test: `node server.js`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] test script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /root/.npm/_logs/2021-01-15T03_08_47_801Z-debug.log

실행하려는 서버 (익스프레스를 추가해도 차이가 없음) :

const io = require('socket.io')(3001,
  {
    cors: 
    {
      origin: "http://127.0.0.1:5500",
      methods: ["GET", "POST"]
    }
  });

const users = {};

io.on('connection', socket => {
  socket.on('new-user', name => {
    users[socket.id] = name;
    socket.broadcast.emit('user-connected', name);
  });
  socket.on('send-chat-message', message => {
    
    socket.broadcast.emit('chat-message', { message: message, name: users[socket.id] });
  });
  socket.on('disconnect', () => {
    socket.broadcast.emit('user-disconnected', users[socket.id]);
    delete users[socket.id];
  });
});

package.son :

{
  "name": "lifenet_temp",
  "version": "1.0.0",
  "description": "Temporary LifeNet Directory",
  "main": "index.js",
  "scripts": {
    "test": "node server.js"
  },
  "author": "1",
  "license": "ISC",
  "dependencies": {
    "express": "^4.17.1",
    "socket.io": "^3.1.0"
  }
}

3001 및 3000 포트 (및 다른 포트)가 그렇지 않은데 왜 호그되고 있는지 잘 모르겠습니다. 많은 감사와 함께 어떤 도움을받을 것입니다. 감사합니다.

네바다

Linux를 사용하는 경우 lsof -ti tcp : 5900 | xargs는 죽입니다. 이것이 작동하지 않으면 컴퓨터를 재부팅하십시오.

이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.

침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제

에서 수정
0

몇 마디 만하겠습니다

0리뷰
로그인참여 후 검토

관련 기사

Related 관련 기사

뜨겁다태그

보관