Server/개발

[Node.js] TCP Socket Server 외부 접속

sangjun-pro 2022. 4. 7. 11:18

이전 포스팅의 프로젝트에서 수정 ( https://sangjunui.tistory.com/16 )

해당 프로젝트는 localhost 동작으로 한 PC 내에서 보내고 받았다.

 

본 포스팅은 [ Client ] - [ 외부망 ] - [ Server ] 로 구현하려하며

외부망 구현은 iptime , DDNS 기능을 사용함 ( 추후 포스팅 예정 )

1. iptime 포트포워딩에서 서버 ip / port  설정

 ( ex ,192.168.150 / 11116 )

 

2. Server 부분 ipaddr 을 공유기에서 전달받은 ip 사용

const ipaddr = '192.168.0.150';
const port = 11116;

 

3. Client 부분 연결 부분 DNS / Port 입력

const client = net.connect({ port: 11116, host: "testDNS.iptime.org" });

 

issue ) Client에서 보낼때 해당 dns 의 address는 받아오나 timeout 등의 응답없음이 뜬다면 방화벽 문제일 확률이 크다.

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

Error: connect ETIMEDOUT ip:port
    at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1159:16)
    at emitErrorNT (internal/streams/destroy.js:106:8)
    at emitErrorCloseNT (internal/streams/destroy.js:74:3)
    at processTicksAndRejections (internal/process/task_queues.js:82:21) {
  errno: -4039,
  code: 'ETIMEDOUT',
  syscall: 'connect',
  address: 'ip',
  port: port
}