HTML

[api] HTML5 - Server-Sent Event - 서버전송이벤트 (= 서버센트이벤트)

목차
  1. Server-Sent Event 예제 (예: open, message)
  2. Server-Sent Event 정의
  3. Server-Sent Event 종류 (= EventSource Object 종류)

 

Server-Sent Event 예제 (예: open, message)

 

<h1 id="hz"></h1>

<div id="s_time"></div>


<script>

if(typeof(EventSource) !== "undefined") { // Server-Sent Event 지원여부 체크

  var source = new EventSource("/server_time.php");

  source.onopen = function() {

    document.getElementById("hz").innerHTML = "홈짱닷컴 (Homzzang.com) 서버갱신시간";

  };

  

  source.onmessage= function(event) {

    document.getElementById("s_time").innerHTML += event.data + "<br>";

  };


} else {

  document.getElementById("s_time").innerHTML = "서버전송이벤트 지원않는 브라우저는 개나 줘버려.";

}

</script>

 


/server_time.php 소스

 

<?php

header('Content-Type: text/event-stream');

header('Cache-Control: no-cache');


$time = date('r');

echo "data: 서버 시간 : {$time}\n\n";

flush();

?>


 

Server-Sent Event 정의

 

서버가 보낸 이벤트는 웹페이지가 자동으로 업데이트되도록 해줌.

 


 

1.
(예) Facebook/Twitter 업데이트, 주가 업데이트, 뉴스 피드, 스포츠 결과 등

 

2.

IE 제외한 주요 최신 브라우저 모두 지원.

 

 

Server-Sent Event 종류 (= EventSource Object 종류)

 

onopen

서버와의 연결이 열린 경우.

 

onmessage

메시지가 수신 될 때.

 

onerror

오류가 발생했을 때.

 


 


분류 제목
attribute HTML - dir 속성 - 텍스트 출력방향 지정 (= dir속성 = 디르속성|디렉션속성)
attribute HTML - async 속성 ★★★ - 비동기적으로 외부스크립트 실행 지정 (= async속성 = 에이싱크속…
attribute HTML - onended 속성 - 미디어 재생 끝날 때 실행 (= onended속성 = 온엔디드속성) ※ …
attribute HTML - translate 속성 - 요소 내용 번역 허용 여부 지정 (= translate속성 = 트랜슬…
attribute HTML - novalidate 속성 - 폼데이터 제출 시, 유효성 평가 생략 (= novalidate속성 …
attribute HTML - for 속성 - <label>/<output> 관련 요소 ID 바인딩 지정 (= for속성 = …
attribute HTML - ontimeupdate 속성 - (오디오/비디오) 재생위치 변경 시 실행 (= ontimeupd…
attribute HTML - open 속성 - <details> 태그 안 세부내용 표시함을 기본으로 지정 (= open속성 …
attribute HTML - border 속성 - (HTML5 지원 X) 테두리 너비 지정 (= border속성 = 보더속성…
attribute HTML - onwheel 속성 - 마우스휠/터치패드휠 움직일 때 실행 (= onwheel속성 = 온휠속성…
attribute HTML - value 속성 ★★★ - 요소값 지정 (= value속성 = 밸류속성) ※ 초기값/기본값/현재…
attribute HTML - contenteditable 속성 - 요소 내용 수정 가능 여부 지정 (= contentedit…
attribute HTML - formtarget 속성 - 폼데이터 전달할 폼 지정 (= formtarget속성 = 폼타겟속성…
attribute HTML - dirname 속성 - input/textarea 요소의 텍스트 방향 지정 (= dirname속…
attribute HTML - class 속성 ★★★ - 클래스명 선택자 지정 (= class속성 = 클래스속성)
10/24
목록
 홈  PC버전 로그인 일본어
그누앞단언어
그누뒷단언어
그외코딩언어
그누보드
제작의뢰
Q&A
커뮤니티
웹유틸
회원센터
홈짱닷컴 PC버전 로그인