Develop/Node.js

[NodeJs-채팅만들기-1] 간단한 로그출력 Server, Client 만들기

GuriZzang 2014. 8. 13. 01:27

server.js

설명은 앞에서도 많이 했으니..

1. app이라는 변수로 서버를 샐행하고 handler라는 함수를 동작시킨다.

2. handler에는

__dirname은 전역변수로 현재 디렉토리를 반환함.

즉 현재 서버가 실행되고 있는 루트의 client.html 파일을 찾아서 읽고 그안의 내용을 본문에 써준다.

즉.. 페이지 이동과 비슷.(내가 이해하고 있는것이 맞음?)

3. 

'news' 라는 변수로 {hello : 'world'}라는 json형태의 데이터를 전송함.


client.html

서버에서 읽는 파일.

1. script 소스 링크는 신경쓸 필요 없음. node_modules 안의 파일을 지가 알아서 찾아 연결함.

(단 node_modules 안에 파일은 존재해야함... 다른곳에 위치한 파일을 링크걸려면 ./ 혹은 / 로 시작하는 경로를 명시)

2. 서버에서 'news'라는 변수로 데이터를 전송하므로 'news'로 데이터를 받아서 console.log(data);로 찍는다.

3. socket.emit(); 은 다시 서버로 데이터를 전송함.


하지만!!!!

이소스 그대로 서버를 실행하면


Server Start!


events.js:72

        throw er; // Unhandled 'error' event

              ^

Error: listen EACCES

    at errnoException (net.js:904:11)

    at Server._listen2 (net.js:1023:19)

    at listen (net.js:1064:10)

    at Server.listen (net.js:1138:5)

    at Object.<anonymous> (D:\03_private\[140728] NodeJs\ChatPractice02\chat01\server.js:5:5)

    at Module._compile (module.js:456:26)

    at Object.Module._extensions..js (module.js:474:10)

    at Module.load (module.js:356:32)

    at Function.Module._load (module.js:312:12)

    at Function.Module.runMain (module.js:497:10)


이런 에러를 만나는 분들이 계실수도 있을게다...




아하하하... 아하하하...

처음 소스를 구하고 실행했을때 나왔던 에러인데 일주일이 지난 지금에서야...

이 에러때문에 Socket.io를 처음부터 공부했다는.. 무려 일주일이나........

하지만 오늘도 같은 에러가 뜸...

열받아서 걍 구글링...




아하하하하~~~~~

일주일이나 삽질했지만 난 틀리지 않았어~

입가에 미소를 띄우지만 마음은 흔들리지... 않았어...




이럴땐.. 당황하지 않고~

app.listen(80)의 포트를 8080혹은 다른 포트로 지정해주면~~~






'Develop > Node.js' 카테고리의 다른 글

[NodeJs-채팅만들기-1] Soket.IO  (0) 2014.08.13
[Nodejs] OS 모듈  (0) 2014.08.01
[6.Nodejs] Node.js 기본 소스분석  (0) 2014.07.30
[6.Nodejs] Node.js 전역변수  (0) 2014.07.30
[6.Nodejs] Node.js Debugger 사용하기.  (0) 2014.07.28