• 회원가입
  • 로그인
  • 구글아이디로 로그인

[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 - 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 - formtarget 속성 - 폼데이터 전달할 폼 지정 (= formtarget속성 = 폼타겟속성…
attribute HTML - contenteditable 속성 - 요소 내용 수정 가능 여부 지정 (= contentedit…
attribute HTML - dirname 속성 - input/textarea 요소의 텍스트 방향 지정 (= dirname속…
attribute HTML - class 속성 ★★★ - 클래스명 선택자 지정 (= class속성 = 클래스속성)
attribute HTML - onscroll 속성 ★ - 마우스 스크롤 이벤트 시 실행 (= onscroll속성 = 온스크롤…
attribute HTML - bgcolor 속성 - (HTML5 지원 X) 배경색 지정 (= bgcolor속성 = 비지컬러속…
attribute HTML - onpaste 속성 - 사용자가 요소에 내용 붙여넣기 시 실행 (= onpaste속성 = 온패스…
attribute HTML - usemap 속성 - 이미지를 이미지맵으로 지정 (= usemap속성 = 유즈맵속성|유스맵속성)
attribute HTML - data 속성 - <object> 태그의 리소스 URL 주소 지정 (= data속성 = 데이터속…
attribute HTML - onfocus 속성 ★ - 포커스 설정 시 실행 (= onfocus속성 = 온포커스속성) ※ o…
form HTML - <input type="range"> 태그 - 지정범위 내 입력값 지정 (= 인풋레인지타입/레인…
attribute HTML - multiple 속성 ★ - 복수 (파일업로드/이메일입력/옵션선택) 허용 (= multiple속…
attribute HTML - target 속성 ★ - (링크된 문서 열 곳 / 폼 제출할 곳) 지정 (= target속성 =…
attribute HTML - maxlength 속성 ★ - 입력 가능한 최대 글자 개수 지정 (= maxlength속성 = …
8/18
목록
찾아주셔서 감사합니다. Since 2012