본문 바로가기
FrontEnd/HTML

server-sent event(SSE) 서버에서 클라이언트로 이벤트 보내기

by 이도현 2021. 6. 17.

같은 회사 직원이 카카오 코딩테스트에서 봤던 문제 중에

서버단에서 대용량 엑셀에 대한 처리를 할 때

현재 진행률을 클라이언트단에서 보여주는 방법을 구현하라는 문제가 있었다고 한다.

 

웹소켓이나 뭔가 다양한 방법들이 있겠지만,

SSE가 HTML5 표준 권고안이라고 하니 이 방식을 따르는 것이 표준일 것 같다.

 

서버에서 보내는 이벤트를 관리하는 표준적인 방법.

스트림 이벤트를 서버에서 프론트 엔드로 보낸다.

일방향 접속이며, 클라이언트에서 서버로 이벤트를 보내지는 못한다.

실제 사용방법은 아래 링크 참조

 

 

https://developer.mozilla.org/en-US/docs/Web/API/Server-sent_events/Using_server-sent_events

 

Using server-sent events - Web APIs | MDN

Developing a web application that uses server-sent events is straightforward. You'll need a bit of code on the server to stream events to the front-end, but the client side code works almost identically to websockets in part of handling incoming events.

developer.mozilla.org

 

https://www.w3schools.com/html/html5_serversentevents.asp

 

HTML Server-Sent Events API

HTML SSE API Server-Sent Events (SSE) allow a web page to get updates from a server. Server-Sent Events - One Way Messaging A server-sent event is when a web page automatically gets updates from a server. This was also possible before, but the web page wou

www.w3schools.com

 

'FrontEnd > HTML' 카테고리의 다른 글

HTML meta 요소는 무엇일까?  (0) 2021.06.29
Location href 와 Location replace() Method  (0) 2021.06.15