devsho
...@@ -75,7 +75,8 @@ app.use(router) // router 정의 ...@@ -75,7 +75,8 @@ app.use(router) // router 정의
75 75
76 // Socket.io 76 // Socket.io
77 io.sockets.on('connection', function(socket) { 77 io.sockets.on('connection', function(socket) {
78 - try{ 78 + var ip = socket.handshake.address;
79 +
79 /* 새로운 유저가 접속했을 경우 다른 소켓에게도 알려줌 */ 80 /* 새로운 유저가 접속했을 경우 다른 소켓에게도 알려줌 */
80 socket.on('newUser', function() { 81 socket.on('newUser', function() {
81 /* 소켓에 이름 저장해두기 */ 82 /* 소켓에 이름 저장해두기 */
...@@ -83,35 +84,38 @@ io.sockets.on('connection', function(socket) { ...@@ -83,35 +84,38 @@ io.sockets.on('connection', function(socket) {
83 var key = socket.handshake.sessionID; 84 var key = socket.handshake.sessionID;
84 85
85 // tempSession[key] = String Type 86 // tempSession[key] = String Type
87 + if(tempSession[key] != undefined){
86 var useSession = JSON.parse(tempSession[key]); 88 var useSession = JSON.parse(tempSession[key]);
87 socket.name = useSession.passport.user.nickname 89 socket.name = useSession.passport.user.nickname
88 - console.log(logString + socket.name+' 님이 접속하였습니다.') 90 + console.log(logString + socket.name+' 님이 접속하였습니다.('+ip+')')
89 91
90 /* 모든 소켓에게 전송 */ 92 /* 모든 소켓에게 전송 */
91 io.sockets.emit('update', {type: 'connect', name: 'SERVER', message:socket.name + '님이 접속하였습니다.'}) 93 io.sockets.emit('update', {type: 'connect', name: 'SERVER', message:socket.name + '님이 접속하였습니다.'})
92 - })
93 - }
94 - catch{
95 - //
96 } 94 }
95 + })
97 96
98 /* 전송한 메시지 받기 */ 97 /* 전송한 메시지 받기 */
99 socket.on('message', function(data) { 98 socket.on('message', function(data) {
99 + if(socket.name != undefined){
100 /* 받은 데이터에 누가 보냈는지 이름을 추가 */ 100 /* 받은 데이터에 누가 보냈는지 이름을 추가 */
101 data.name = socket.name 101 data.name = socket.name
102 102
103 - console.log(data)
104 -
105 /* 보낸 사람을 제외한 나머지 유저에게 메시지 전송 */ 103 /* 보낸 사람을 제외한 나머지 유저에게 메시지 전송 */
106 socket.broadcast.emit('update', data); 104 socket.broadcast.emit('update', data);
105 + }
106 + else{
107 + console.log(logString+'익명 유저의 채팅 전송을 거부했습니다.('+ip+')')
108 + //
109 + }
107 }) 110 })
108 111
109 /* 접속 종료 */ 112 /* 접속 종료 */
110 socket.on('disconnect', function() { 113 socket.on('disconnect', function() {
114 + if(socket.name != undefined){
111 console.log(logString+socket.name + ' 님이 나가셨습니다.') 115 console.log(logString+socket.name + ' 님이 나가셨습니다.')
112 -
113 /* 나가는 사람을 제외한 나머지 유저에게 메시지 전송 */ 116 /* 나가는 사람을 제외한 나머지 유저에게 메시지 전송 */
114 socket.broadcast.emit('update', {type: 'disconnect', name: 'SERVER', message: socket.name + '님이 나가셨습니다.'}); 117 socket.broadcast.emit('update', {type: 'disconnect', name: 'SERVER', message: socket.name + '님이 나가셨습니다.'});
118 + }
115 }) 119 })
116 }) 120 })
117 121
......
...@@ -61,15 +61,15 @@ create table board( ...@@ -61,15 +61,15 @@ create table board(
61 >UPDATE board SET idx = @COUNT:=@COUNT+1; 61 >UPDATE board SET idx = @COUNT:=@COUNT+1;
62 62
63 --- 63 ---
64 -### 최종 수정: 2021-11-25 17:57<br> 64 +### 최종 수정: 2021-11-25 18:48<br>
65 ### 수정 내용: 65 ### 수정 내용:
66 0. 사용자-서버 채팅간 여백 66 0. 사용자-서버 채팅간 여백
67 0. 채팅 엔터키 67 0. 채팅 엔터키
68 -0. 채팅(socket) 사용 중 서버 재시작 시 서버 오류
69 1. 채팅 구현 68 1. 채팅 구현
70 2. 시간 실시간 반영 69 2. 시간 실시간 반영
71 3. 프로필 사진 추가 70 3. 프로필 사진 추가
72 4. 프로필 검색 추가 71 4. 프로필 검색 추가
73 5. 프로필 비주얼 업데이트 72 5. 프로필 비주얼 업데이트
74 -6. 코드 다듬음
75 -7. 버그 수정
...\ No newline at end of file ...\ No newline at end of file
73 +6. 채팅(socket) 사용 중 서버 재시작 시 서버 오류 해결
74 +7. 코드 다듬음
75 +8. 버그 수정
...\ No newline at end of file ...\ No newline at end of file
......
...@@ -263,7 +263,6 @@ router.post('/upload', upload.single('userfile'), function(req,res){ ...@@ -263,7 +263,6 @@ router.post('/upload', upload.single('userfile'), function(req,res){
263 } 263 }
264 }) 264 })
265 265
266 -
267 function popup(){ 266 function popup(){
268 var url = "/profile/upload"; 267 var url = "/profile/upload";
269 var name = "파일 업로드"; 268 var name = "파일 업로드";
...@@ -278,11 +277,4 @@ function enterkey() { ...@@ -278,11 +277,4 @@ function enterkey() {
278 } 277 }
279 } 278 }
280 279
281 -function enterkey() {
282 - if (window.event.keyCode == 13) {
283 - // 엔터키가 눌렸을 때 실행할 내용
284 - send();
285 - }
286 -}
287 -
288 module.exports = router; 280 module.exports = router;
...\ No newline at end of file ...\ No newline at end of file
......