-
Notifications
You must be signed in to change notification settings - Fork 1
Open
Labels
Description
문제점
server에 연결 후 데이터 요청시
- 데이터가 두번 나눠서 받는 경우가 있다.
- 데이터가 두번 나눠서 받는 경우 JSON.parse가 동작을 하지를 못한다.
코드
client.on('data', function (data) {
console.log(data.length);
console.log(JSON.parse(data.toString())); // error 위치
client.end();
});결과
// 데이터를 두번 나눠서 받는 경우
undefined:1
lication_1409186885665_0039", "host_ip": "192.168.10.3", "app_master_id": "con
^
SyntaxError: Unexpected end of input
at Object.parse (native)
at Socket. (/workspace/webTest/lavenderTest/a_test.js:27:22)
at Socket.EventEmitter.emit (events.js:95:17)
at Socket. (_stream_readable.js:746:14)
at Socket.EventEmitter.emit (events.js:92:17)
at emitReadable_ (_stream_readable.js:408:10)
at emitReadable (_stream_readable.js:404:5)
at readableAddChunk (_stream_readable.js:165:9)
at Socket.Readable.push (_stream_readable.js:127:10)
at TCP.onread (net.js:526:21)
// 정상 처리 경우
// 한번에 모든 데이터 받는 경우 정상적으로 JSON.parse처리가 된다.
{ SEQ_NO: 0,
RESULT:
[ { status: 'running',
count: '4',
container_log: '/Lavender/usr/thirdparty/hadoop-2.4.0/logs/userlogs/application_1409186885665_0038/container_1409186885665_0038_01_000001',
app_name: 'collector',
start_time: '20140923023553',
app_id: 'application_1409186885665_0038',
host_ip: '192.168.10.3',
app_master_id: 'container_1409186885665_0038_01_000001',
host_name: 'slave2',
_id: '5420dc896d987fb1009e8e66',
containers: [Object],
end_time: 'N/A' },
{ status: 'running',
count: '4',
container_log: '/Lavender/usr/thirdparty/hadoop-2.4.0/logs/userlogs/application_1409186885665_0039/container_1409186885665_0039_01_000001',
app_name: 'parser',
start_time: '20140923023632',
app_id: 'application_1409186885665_0039',
host_ip: '192.168.10.3',
app_master_id: 'container_1409186885665_0039_01_000001',
host_name: 'slave2',
_id: '5420dcb06d987fb1009e8e67',
containers: [Object],
end_time: 'N/A' } ],
RESULT_CODE: 0 }