NODE.JS.SERVER를 이용한 조회/실시간 통합(4)

1. NODE.JS.SERVER를 이용한 SQLite조회 (3)버젼
2. NODE.JS.SERVER를 이용한 실시간데이타 반영 (2)버젼
3. NODE.JS.SERVER를 이용한 조회/실시간 통합(4)

1과 2를 3으로 통합할수 있는 핵심은, 1번의 주고받는 REDIS.QUEUE.NAME과
2번의 주고받는 REDIS.QUEUE.NAME의 PREFIX를 틀리게 운용하면 된다.

조회시에는
SEQRCHSEND:클라이언트고유키, SEQRCHRECV:클라이언트고유키
실시간에는
SEND:클라이언트고유키, RECV:클라이언트고유키

물론 REDIS에 데이타를 제공하는 REDIS.TICKER.SERVER또한 한쌍의 주고받는 부분의 로직이 추가되어야 한다.

개략적인구조)


여러개의.브라우져에서.각각.조회가.가능하며, 실시간 PUSH는 모든 브라우져에 적용된다.)


PUSH데이타.실시간.데이타화면)

버튼을 통해서 SQLite의 데이타를 가져오는 화면)

app.js
0.00MB
index.html
0.05MB

석수컴퓨터 학원에서는 아래와 같은 궁금증을 가지고 계신분들에게 온라인으로 가이드해드립니다.

1. KRX정보분배 데이타 포맷에 대해서 궁금하신분
2. KRX정보분배 데이타를 직접 받아보고 싶으신분(증권,파생,지수등)
3. KRX정보분배 데이타를 수신하기 위한 최적화되어진 TCP환경에 대해서 알고싶으신분
4. 데이타를 파싱을 위한 구조체 핸들링을 알고싶으신분(c,c#)
5. 데이타를 저장하는 방법을 알고싶으신분(MySQL, SQLite, REDIS)
6. KRX정보분배 데이타의 실시간 PUSH방법을 알고싶으신분(HTS,WTS등)
7. 위와 관련되어진 서버나 클라이언트에 대해서 궁금증을 가지고 계신분

xterm92@naver.com 으로 문의주시면 성심성의껏 답변드리겠습니다.

Node.Server/Index.HTML(2)+(3)

app.js
0.00MB
index.html
0.05MB

Node app.js 를 통한 REDIS에서 데이타 조회 (SQLite DataBase에 저장되어진 시세데이타를 불러오기, 실시간이 아님)

1. index.html에서 app.js로 데이타포맷 보내기(SQLite DataBase에 저장되어진 시세데이타를 불러오기, 실시간이 아님)
        async function sendData() {

            const data = {
                proto: "r",
                sender: "1127001637919216845106",
                id: "QUERY.0001574960.001",
                ts: new Date().toISOString(),
                method: "",
                query: "A301S",
                colcnt: ""
            };

            const response = await fetch('/send', {
                method: 'POST',
                headers: {
                    'Content-Type': 'application/json'
                },
                body: JSON.stringify(data)
            });
            const result = await response.json();
        }
2. REDIS에서 app.js 를 통한 JSON데이타 하나씩 꺼내오기
3  index.html에서 반복문을 통해서 하나씩 테이블에 출력
3.1 - index.html이 주된 메인이 되어서 control하므로, 반복문을 빠져나올수 있는 이벤트가 필요함
3.2 - JSON포맷중에 남은 항목에 서버에서 호출되어진 데이타의 Total개수를 표시
index++;
console.log(`Index: ${index}, Data Result: ${data.result}`);
if (data.result == index)
{
console.log(`Index: ${index}, Data Result: ${data.result}`);
console.log(`Index: ${index}, Data Result: ${data.result}`);
break;
}

4. 정상적으로 조회가 되는것을 확인

app.js
0.00MB
index.html
0.03MB

Node app.js 를 통한 REDIS에서 데이타 추출(삭제후에 꺼내오기)

개요)
- REDIS에 QUEUE에 매칭되어진 데이타가 쌓이면 실시간으로 NODE.js에서 이벤트.수신하여
웹브라우져와 통신하여, 브라우져에 표현해준다.(실시간.웹소켓)



app.js
- REDIS에서 데이타 추출(삭제후에 꺼내오기)
// Function to fetch data from Redis list using BLPOP (blocking pop)
async function fetchDataFromRedis() {
    try {
        const result = await redisClient.blPop('QCS:1127001637919216817849', 0); // 0 means it will block until data is available
        if (result) {
            // result is [key, value] where value is the data we want
            const data = JSON.parse(result.element);
            return Array.isArray(data) ? data : [data]; // Ensure data is an array
        }
    } catch (err) {
        console.error('Error fetching data from Redis:', err);
    }
    return [];
}

index.html 
- 웹소켓을 통한 데이타 표시


비고)
마지막에 입력되어진 데이타가 제일 위에 위치한다.
그러므로, 헤더의 타이틀과 맞아떨어질수 있다.


app.js
0.00MB
index.html
0.03MB

 

redis-cli에서 키가 리스트인지 확인하려면 TYPE 명령어를 사용하면 됩니다. Redis에서 특정 키의 데이터 유형을 확인할 수 있는 명령어입니다.

TYPE <key>

예시:

TYPE mylist

이 명령어는 해당 키가 리스트일 경우 list라는 값을 반환합니다.

나의 말:
127.0.0.1:6379> TYPE QCS:11270016379127001 list 127.0.0.1:6379> 리스트일경우 데이타 존재여부 확인하기
 

Redis에서 리스트에 데이터가 있는지 확인하려면 LLEN 명령어를 사용하여 해당 리스트의 길이를 확인할 수 있습니다. 길이가 0이면 데이터가 없다는 의미이고, 0보다 크면 데이터가 있다는 의미입니다.

LLEN <key>

예시:

LLEN QCS:11270016379127001

이 명령어는 리스트의 요소 개수를 반환합니다. 반환 값이 0이면 리스트에 데이터가 없는 것이고, 0보다 크면 데이터가 존재하는 것입니다.

 
 

Redis에서 리스트의 데이터를 확인하려면 LRANGE 명령어를 사용합니다. 이 명령어는 리스트의 특정 범위 내에 있는 요소들을 반환합니다.

형식:

LRANGE <key> <start> <stop>
  • start: 시작 인덱스 (0부터 시작)
  • stop: 끝 인덱스 (-1은 리스트의 마지막 요소까지를 의미)

예시로, 리스트의 모든 데이터를 확인하려면:

LRANGE QCS:11270016379127001 0 -1

이 명령어는 리스트 QCS:11270016379127001의 모든 요소를 반환합니다.


127.0.0.1:6379> TYPE QCS:11270016379127001
list
127.0.0.1:6379> LLEN QCS:11270016379127001
(integer) 63
127.0.0.1:6379>
127.0.0.1:6379> LRANGE QCS:11270016379127001 0 -1
 1) "{\"proto\":\"response/json\",\"sender\":\"11270016379127001\",\"id\":null,\"ts\":\"[2024-09-30 08:31:04.523]\",\"method\":\"realkrx\",\"query\":\"A301S\",\"data\":\"{\\\"dataClass\\\":\\\"A3\\\",\\\"infoMarketClass\\\":\\\"01S\\\",\\\"distributeStockIndex\\\":\\\"        \\\",\\\"boardID\\\":\\\"G1\\\",\\\"sessionID\\\":\\\"40\\\",\\\"stockCode\\\":\\\"KR7005930003\\\",\\\"stockSeq\\\":\\\"000379\\\",\\\"transactionProcessingTime\\\":\\\"090016340616\\\",\\\"upDown\\\":\\\"2\\\",\\\"gap\\\":\\\"00000000600\\\",\\\"tradePrice\\\":\\\"00000065900\\\",\\\"tradeVolume\\\":\\\"0000000014\\\",\\\"openPrice\\\":\\\"00000065900\\\",\\\"highPrice\\\":\\\"00000066000\\\",\\\"lowPrice\\\":\\\"00000065800\\\",\\\"accmTradeVolume\\\":\\\"000000740706\\\",\\\"accmTradeAmount\\\":\\\"000000048808907100.000\\\",\\\"lastAskBidClassCode\\\":\\\"1\\\",\\\"LPHoldingVolume\\\":\\\"000000000000000\\\",\\\"askOneQuote\\\":\\\"00000066000\\\",\\\"bidOneQuote\\\":\\\"00000065900\\\",\\\"endText\\\":\\\"NULL\\\"}\",\"result\":\"SUCC\"}"
 2) "{\"proto\":\"response/json\",\"sender\":\"11270016379127001\",\"id\":null,\"ts\":\"[2024-09-30 08:31:04.541]\",\"method\":\"realkrx\",\"query\":\"A301S\",\"data\":\"{\\\"dataClass\\\":\\\"A3\\\",\\\"infoMarketClass\\\":\\\"01S\\\",\\\"distributeStockIndex\\\":\\\"        \\\",\\\"boardID\\\":\\\"G1\\\",\\\"sessionID\\\":\\\"40\\\",\\\"stockCode\\\":\\\"KR7005930003\\\",\\\"stockSeq\\\":\\\"000379\\\",\\\"transactionProcessingTime\\\":\\\"090203148634\\\",\\\"upDown\\\":\\\"2\\\",\\\"gap\\\":\\\"00000000300\\\",\\\"tradePrice\\\":\\\"00000065600\\\",\\\"tradeVolume\\\":\\\"0000000001\\\",\\\"openPrice\\\":\\\"00000065900\\\",\\\"highPrice\\\":\\\"00000066000\\\",\\\"lowPrice\\\":\\\"00000065600\\\",\\\"accmTradeVolume\\\":\\\"000001311321\\\",\\\"accmTradeAmount\\\":\\\"000000086341981200.000\\\",\\\"lastAskBidClassCode\\\":\\\"1\\\",\\\"LPHoldingVolume\\\":\\\"000000000000000\\\",\\\"askOneQuote\\\":\\\"00000065700\\\",\\\"bidOneQuote\\\":\\\"00000065600\\\",\\\"endText\\\":\\\"NULL\\\"}\",\"result\":\"SUCC\"}"
 3) "{\"proto\":\"response/json\",\"sender\":\"11270016379127001\",\"id\":null,\"ts\":\"[2024-09-30 08:31:04.556]\",\"method\":\"realkrx\",\"query\":\"A301S\",\"data\":\"{\\\"dataClass\\\":\\\"A3\\\",\\\"infoMarketClass\\\":\\\"01S\\\",\\\"distributeStockIndex\\\":\\\"        \\\",\\\"boardID\\\":\\\"G1\\\",\\\"sessionID\\\":\\\"40\\\",\\\"stockCode\\\":\\\"KR7005930003\\\",\\\"stockSeq\\\":\\\"000379\\\",\\\"transactionProcessingTime\\\":\\\"090423001705\\\",\\\"upDown\\\":\\\"2\\\",\\\"gap\\\":\\\"00000000400\\\",\\\"tradePrice\\\":\\\"00000065700\\\",\\\"tradeVolume\\\":\\\"0000000001\\\",\\\"openPrice\\\":\\\"00000065900\\\",\\\"highPrice\\\":\\\"00000066000\\\",\\\"lowPrice\\\":\\\"00000065600\\\",\\\"accmTradeVolume\\\":\\\"000001580913\\\",\\\"accmTradeAmount\\\":\\\"000000104057729600.000\\\",\\\"lastAskBidClassCode\\\":\\\"1\\\",\\\"LPHoldingVolume\\\":\\\"000000000000000\\\",\\\"askOneQuote\\\":\\\"00000000000\\\",\\\"bidOneQuote\\\":\\\"00000000000\\\",\\\"endText\\\":\\\"NULL\\\"}\",\"result\":\"SUCC\"}"
 4) "{\"proto\":\"response/json\",\"sender\":\"11270016379127001\",\"id\":null,\"ts\":\"[2024-09-30 08:31:04.575]\",\"method\":\"realkrx\",\"query\":\"A301S\",\"data\":\"{\\\"dataClass\\\":\\\"A3\\\",\\\"infoMarketClass\\\":\\\"01S\\\",\\\"distributeStockIndex\\\":\\\"        \\\",\\\"boardID\\\":\\\"G1\\\",\\\"sessionID\\\":\\\"40\\\",\\\"stockCode\\\":\\\"KR7005930003\\\",\\\"stockSeq\\\":\\\"000379\\\",\\\"transactionProcessingTime\\\":\\\"090645718364\\\",\\\"upDown\\\":\\\"2\\\",\\\"gap\\\":\\\"00000000500\\\",\\\"tradePrice\\\":\\\"00000065800\\\",\\\"tradeVolume\\\":\\\"0000000014\\\",\\\"openPrice\\\":\\\"00000065900\\\",\\\"highPrice\\\":\\\"00000066000\\\",\\\"lowPrice\\\":\\\"00000065600\\\",\\\"accmTradeVolume\\\":\\\"000002214961\\\",\\\"accmTradeAmount\\\":\\\"000000145771622700.000\\\",\\\"lastAskBidClassCode\\\":\\\"2\\\",\\\"LPHoldingVolume\\\":\\\"000000000000000\\\",\\\"askOneQuote\\\":\\\"00000065800\\\",\\\"bidOneQuote\\\":\\\"00000065700\\\",\\\"endText\\\":\\\"NULL\\\"}\",\"result\":\"SUCC\"}"
 5) "{\"proto\":\"response/json\",\"sender\":\"11270016379127001\",\"id\":null,\"ts\":\"[2024-09-30 08:31:04.596]\",\"method\":\"realkrx\",\"query\":\"A301S\",\"data\":\"{\\\"dataClass\\\":\\\"A3\\\",\\\"infoMarketClass\\\":\\\"01S\\\",\\\"distributeStockIndex\\\":\\\"        \\\",\\\"boardID\\\":\\\"G1\\\",\\\"sessionID\\\":\\\"40\\\",\\\"stockCode\\\":\\\"KR7005930003\\\",\\\"stockSeq\\\":\\\"000379\\\",\\\"transactionProcessingTime\\\":\\\"091029485349\\\",\\\"upDown\\\":\\\"2\\\",\\\"gap\\\":\\\"00000000200\\\",\\\"tradePrice\\\":\\\"00000065500\\\",\\\"tradeVolume\\\":\\\"0000000005\\\",\\\"openPrice\\\":\\\"00000065900\\\",\\\"highPrice\\\":\\\"00000066000\\\",\\\"lowPrice\\\":\\\"00000065400\\\",\\\"accmTradeVolume\\\":\\\"000002682855\\\",\\\"accmTradeAmount\\\":\\\"000000176459947500.000\\\",\\\"lastAskBidClassCode\\\":\\\"1\\\",\\\"LPHoldingVolume\\\":\\\"000000000000000\\\",\\\"askOneQuote\\\":\\\"00000065600\\\",\\\"bidOneQuote\\\":\\\"00000065500\\\",\\\"endText\\\":\\\"NULL\\\"}\",\"result\":\"SUCC\"}"
 6) "{\"proto\":\"response/json\",\"sender\":\"11270016379127001\",\"id\":null,\"ts\":\"[2024-09-30 08:31:04.650]\",\"method\":\"realkrx\",\"query\":\"A301S\",\"data\":\"{\\\"dataClass\\\":\\\"A3\\\",\\\"infoMarketClass\\\":\\\"01S\\\",\\\"distributeStockIndex\\\":\\\"        \\\",\\\"boardID\\\":\\\"G1\\\",\\\"sessionID\\\":\\\"40\\\",\\\"stockCode\\\":\\\"KR7005930003\\\",\\\"stockSeq\\\":\\\"000379\\\",\\\"transactionProcessingTime\\\":\\\"091358828653\\\",\\\"upDown\\\":\\\"2\\\",\\\"gap\\\":\\\"00000000200\\\",\\\"tradePrice\\\":\\\"00000065500\\\",\\\"tradeVolume\\\":\\\"0000000002\\\",\\\"openPrice\\\":\\\"00000065900\\\",\\\"highPrice\\\":\\\"00000066000\\\",\\\"lowPrice\\\":\\\"00000065400\\\",\\\"accmTradeVolume\\\":\\\"000003115219\\\",\\\"accmTradeAmount\\\":\\\"000000204794064000.000\\\",\\\"lastAskBidClassCode\\\":\\\"1\\\",\\\"LPHoldingVolume\\\":\\\"000000000000000\\\",\\\"askOneQuote\\\":\\\"00000000000\\\",\\\"bidOneQuote\\\":\\\"00000000000\\\",\\\"endText\\\":\\\"NULL\\\"}\",\"result\":\"SUCC\"}"
 7) "{\"proto\":\"response/json\",\"sender\":\"11270016379127001\",\"id\":null,\"ts\":\"[2024-09-30 08:31:04.712]\",\"method\":\"realkrx\",\"query\":\"A301S\",\"data\":\"{\\\"dataClass\\\":\\\"A3\\\",\\\"infoMarketClass\\\":\\\"01S\\\",\\\"distributeStockIndex\\\":\\\"        \\\",\\\"boardID\\\":\\\"G1\\\",\\\"sessionID\\\":\\\"40\\\",\\\"stockCode\\\":\\\"KR7005930003\\\",\\\"stockSeq\\\":\\\"000379\\\",\\\"transactionProcessingTime\\\":\\\"091825878686\\\",\\\"upDown\\\":\\\"2\\\",\\\"gap\\\":\\\"00000000200\\\",\\\"tradePrice\\\":\\\"00000065500\\\",\\\"tradeVolume\\\":\\\"0000000093\\\",\\\"openPrice\\\":\\\"00000065900\\\",\\\"highPrice\\\":\\\"00000066000\\\",\\\"lowPrice\\\":\\\"00000065400\\\",\\\"accmTradeVolume\\\":\\\"000003385914\\\",\\\"accmTradeAmount\\\":\\\"000000222525294200.000\\\",\\\"lastAskBidClassCode\\\":\\\"1\\\",\\\"LPHoldingVolume\\\":\\\"000000000000000\\\",\\\"askOneQuote\\\":\\\"00000065600\\\",\\\"bidOneQuote\\\":\\\"00000065500\\\",\\\"endText\\\":\\\"NULL\\\"}\",\"result\":\"SUCC\"}"
 8) "{\"proto\":\"response/json\",\"sender\":\"11270016379127001\",\"id\":null,\"ts\":\"[2024-09-30 08:31:04.774]\",\"method\":\"realkrx\",\"query\":\"A301S\",\"data\":\"{\\\"dataClass\\\":\\\"A3\\\",\\\"infoMarketClass\\\":\\\"01S\\\",\\\"distributeStockIndex\\\":\\\"        \\\",\\\"boardID\\\":\\\"G1\\\",\\\"sessionID\\\":\\\"40\\\",\\\"stockCode\\\":\\\"KR7005930003\\\",\\\"stockSeq\\\":\\\"000379\\\",\\\"transactionProcessingTime\\\":\\\"092352815143\\\",\\\"upDown\\\":\\\"2\\\",\\\"gap\\\":\\\"00000000200\\\",\\\"tradePrice\\\":\\\"00000065500\\\",\\\"tradeVolume\\\":\\\"0000000004\\\",\\\"openPrice\\\":\\\"00000065900\\\",\\\"highPrice\\\":\\\"00000066000\\\",\\\"lowPrice\\\":\\\"00000065400\\\",\\\"accmTradeVolume\\\":\\\"000003808293\\\",\\\"accmTradeAmount\\\":\\\"000000250189888900.000\\\",\\\"lastAskBidClassCode\\\":\\\"1\\\",\\\"LPHoldingVolume\\\":\\\"000000000000000\\\",\\\"askOneQuote\\\":\\\"00000065600\\\",\\\"bidOneQuote\\\":\\\"00000065500\\\",\\\"endText\\\":\\\"NULL\\\"}\",\"result\":\"SUCC\"}"
 9) "{\"proto\":\"response/json\",\"sender\":\"11270016379127001\",\"id\":null,\"ts\":\"[2024-09-30 08:31:04.828]\",\"method\":\"realkrx\",\"query\":\"A301S\",\"data\":\"{\\\"dataClass\\\":\\\"A3\\\",\\\"infoMarketClass\\\":\\\"01S\\\",\\\"distributeStockIndex\\\":\\\"        \\\",\\\"boardID\\\":\\\"G1\\\",\\\"sessionID\\\":\\\"40\\\",\\\"stockCode\\\":\\\"KR7005930003\\\",\\\"stockSeq\\\":\\\"000379\\\",\\\"transactionProcessingTime\\\":\\\"092833652644\\\",\\\"upDown\\\":\\\"2\\\",\\\"gap\\\":\\\"00000000100\\\",\\\"tradePrice\\\":\\\"00000065400\\\",\\\"tradeVolume\\\":\\\"0000000001\\\",\\\"openPrice\\\":\\\"00000065900\\\",\\\"highPrice\\\":\\\"00000066000\\\",\\\"lowPrice\\\":\\\"00000065400\\\",\\\"accmTradeVolume\\\":\\\"000003989750\\\",\\\"accmTradeAmount\\\":\\\"000000262063533100.000\\\",\\\"lastAskBidClassCode\\\":\\\"1\\\",\\\"LPHoldingVolume\\\":\\\"000000000000000\\\",\\\"askOneQuote\\\":\\\"00000000000\\\",\\\"bidOneQuote\\\":\\\"00000000000\\\",\\\"endText\\\":\\\"NULL\\\"}\",\"result\":\"SUCC\"}"
10) "{\"proto\":\"response/json\",\"sender\":\"11270016379127001\",\"id\":null,\"ts\":\"[2024-09-30 08:31:04.894]\",\"method\":\"realkrx\",\"query\":\"A301S\",\"data\":\"{\\\"dataClass\\\":\\\"A3\\\",\\\"infoMarketClass\\\":\\\"01S\\\",\\\"distributeStockIndex\\\":\\\"        \\\",\\\"boardID\\\":\\\"G1\\\",\\\"sessionID\\\":\\\"40\\\",\\\"stockCode\\\":\\\"KR7005930003\\\",\\\"stockSeq\\\":\\\"000379\\\",\\\"transactionProcessingTime\\\":\\\"093141775147\\\",\\\"upDown\\\":\\\"2\\\",\\\"gap\\\":\\\"00000000100\\\",\\\"tradePrice\\\":\\\"00000065400\\\",\\\"tradeVolume\\\":\\\"0000000001\\\",\\\"openPrice\\\":\\\"00000065900\\\",\\\"highPrice\\\":\\\"00000066000\\\",\\\"lowPrice\\\":\\\"00000065300\\\",\\\"accmTradeVolume\\\":\\\"000004124641\\\",\\\"accmTradeAmount\\\":\\\"000000270882461600.000\\\",\\\"lastAskBidClassCode\\\":\\\"2\\\",\\\"LPHoldingVolume\\\":\\\"000000000000000\\\",\\\"askOneQuote\\\":\\\"00000065400\\\",\\\"bidOneQuote\\\":\\\"00000065300\\\",\\\"endText\\\":\\\"NULL\\\"}\",\"result\":\"SUCC\"}"
11) "{\"proto\":\"response/json\",\"sender\":\"11270016379127001\",\"id\":null,\"ts\":\"[2024-09-30 08:31:04.954]\",\"method\":\"realkrx\",\"query\":\"A301S\",\"data\":\"{\\\"dataClass\\\":\\\"A3\\\",\\\"infoMarketClass\\\":\\\"01S\\\",\\\"distributeStockIndex\\\":\\\"        \\\",\\\"boardID\\\":\\\"G1\\\",\\\"sessionID\\\":\\\"40\\\",\\\"stockCode\\\":\\\"KR7005930003\\\",\\\"stockSeq\\\":\\\"000379\\\",\\\"transactionProcessingTime\\\":\\\"093441844187\\\",\\\"upDown\\\":\\\"3\\\",\\\"gap\\\":\\\"00000000000\\\",\\\"tradePrice\\\":\\\"00000065300\\\",\\\"tradeVolume\\\":\\\"0000000018\\\",\\\"openPrice\\\":\\\"00000065900\\\",\\\"highPrice\\\":\\\"00000066000\\\",\\\"lowPrice\\\":\\\"00000065300\\\",\\\"accmTradeVolume\\\":\\\"000004150310\\\",\\\"accmTradeAmount\\\":\\\"000000272560309900.000\\\",\\\"lastAskBidClassCode\\\":\\\"1\\\",\\\"LPHoldingVolume\\\":\\\"000000000000000\\\",\\\"askOneQuote\\\":\\\"00000065400\\\",\\\"bidOneQuote\\\":\\\"00000065300\\\",\\\"endText\\\":\\\"NULL\\\"}\",\"result\":\"SUCC\"}"
12) "{\"proto\":\"response/json\",\"sender\":\"11270016379127001\",\"id\":null,\"ts\":\"[2024-09-30 08:31:05.021]\",\"method\":\"realkrx\",\"query\":\"A301S\",\"data\":\"{\\\"dataClass\\\":\\\"A3\\\",\\\"infoMarketClass\\\":\\\"01S\\\",\\\"distributeStockIndex\\\":\\\"        \\\",\\\"boardID\\\":\\\"G1\\\",\\\"sessionID\\\":\\\"40\\\",\\\"stockCode\\\":\\\"KR7005930003\\\",\\\"stockSeq\\\":\\\"000379\\\",\\\"transactionProcessingTime\\\":\\\"093902993906\\\",\\\"upDown\\\":\\\"3\\\",\\\"gap\\\":\\\"00000000000\\\",\\\"tradePrice\\\":\\\"00000065300\\\",\\\"tradeVolume\\\":\\\"0000000003\\\",\\\"openPrice\\\":\\\"00000065900\\\",\\\"highPrice\\\":\\\"00000066000\\\",\\\"lowPrice\\\":\\\"00000065300\\\",\\\"accmTradeVolume\\\":\\\"000004207435\\\",\\\"accmTradeAmount\\\":\\\"000000276294077300.000\\\",\\\"lastAskBidClassCode\\\":\\\"1\\\",\\\"LPHoldingVolume\\\":\\\"000000000000000\\\",\\\"askOneQuote\\\":\\\"00000065400\\\",\\\"bidOneQuote\\\":\\\"00000065300\\\",\\\"endText\\\":\\\"NULL\\\"}\",\"result\":\"SUCC\"}"



Windows에서 Node.js 서버를 실행하고 클라이언트 측에서 실시간 데이터를 확인하는 방법은 여러 가지가 있습니다. 여기서는 기본적인 설정 방법과 함께 Socket.IO를 이용한 실시간 데이터 전송 예제를 소개하겠습니다.

1. Node.js 설치

먼저 Node.js를 설치해야 합니다. Node.js 공식 웹사이트에서 설치 파일을 다운로드하여 설치합니다.

2. 새로운 Node.js 프로젝트 생성

터미널 또는 명령 프롬프트를 열고, 프로젝트 디렉토리를 생성한 후 이동합니다.

bash
코드 복사
mkdir my-node-server cd my-node-server npm init -y

3. 필요한 패키지 설치

Express와 Socket.IO를 설치합니다.

bash
코드 복사
npm install express socket.io


아래는 Node.js 서버를 실행하고 클라이언트 측에서 실시간 데이터를 확인하는 방법입니다.

4. 프로젝트 구조 만들기

먼저, 프로젝트 폴더를 설정합니다. 아래와 같은 구조를 만들어 주세요:

csharp
코드 복사
redis_web_4_1_ticker/
├── app.js # 서버 측 코드
└── public/
└── index.html # 클라이언트 측 HTML

    4.1. app.js 파일 설정

app.js 파일에 아래 코드를 입력하세요:

    4.2. index.html 파일 설정

public/index.html 파일에 아래 코드를 입력하세요:

    4.3. 프로젝트에 필요한 패키지 설치

프로젝트 폴더에서 터미널(명령 프롬프트)을 열고 다음 명령어를 실행하여 필요한 패키지를 설치합니다:

npm init -y npm install express @redis/client ws

5. Redis 서버 실행

Redis 서버가 실행되고 있는지 확인하세요. Redis 서버가 설치되어 있어야 하고, 실행 중이어야 합니다. 만약 Redis가 설치되지 않았다면, Redis 설치 가이드를 참고하세요.

6. Node.js 서버 실행

터미널에서 다음 명령어를 실행하여 Node.js 서버를 시작합니다:

 
node app.js

서버가 성공적으로 시작되면 다음과 같은 메시지가 표시됩니다:
HTTP Server is running at http://localhost:3000

7. 클라이언트 웹 페이지 열기

웹 브라우저를 열고 다음 URL로 이동합니다:

 
http://localhost:3000/

이제 웹 페이지가 열리고, Redis에서 데이터를 수신하여 테이블에 표시하는 것을 확인할 수 있습니다.
REDIS시세 데이타 단순조회)

 

 

 


화면) 노드서버 실행

app.js
0.00MB
index.html
0.03MB


/*--------------------------------------------------------------------*/
/*--------------------------------------------------------------------*/
FILENAME:TrisProblem.java
Compile:javac TrisProblem.java
Execution: java TrisProblem.class
/*--------------------------------------------------------------------*/
/*--------------------------------------------------------------------*/

/*--------------------------------------------------------------------*/
package Tris.TrisPackage

/*--------------------------------------------------------------------*/
import java.io.Console;
/*--------------------------------------------------------------------*/
/*--------------------------------------------------------------------*/
class TrisProblem
{
public static void main(String[] args) 
{
//System.out.println("Hello World!");
TrisCls nm = new TrisCls();
nm.running();
}
}

/*--------------------------------------------------------------------*/
/*--------------------------------------------------------------------*/
class TrisCls
{
//definition
final int MAPY=22;
final int MAPX=40;
final int MAXDESIGN=10;
final int ARR=3;
final int D_RRIGHT=1000;
final int D_LEFT=1002;
final int D_DOWN=1003;
final int TRUE=1;
final int FAIL=0;

//variables
int[][] tris = new int[MAPY][MAPX];
int[][] design = new int[ARR][ARR];
int xpos,ypos,score;
int hyun,next;

//int[][][] realdesign = new int[MAXDESIGN][ARR][ARR];
int[][][] realdesign =
{
{{1,1,1},{1,1,1},{1,1,1}},
{{1,1,1},{1,1,1},{1,1,1}},
{{1,1,1},{1,1,1},{1,1,1}},
{{1,1,1},{1,1,1},{1,1,1}},
{{1,1,1},{1,1,1},{1,1,1}},
{{1,1,1},{1,1,1},{1,1,1}},
{{1,1,1},{1,1,1},{1,1,1}},
{{1,1,1},{1,1,1},{1,1,1}},
{{1,1,1},{1,1,1},{1,1,1}},
{{1,1,1},{1,1,1},{1,1,1}}
};
//control

//method
public void running()
{
//
}
}
/*--------------------------------------------------------------------*/
/*--------------------------------------------------------------------*/

+ Recent posts