Cyclone SSE服務(wù)器事件廣播服務(wù)器
Cyclone SSE 是一個(gè) Server-Sent Events (EventSource) 廣播服務(wù)器,基于 Cyclone Web 服務(wù)器構(gòu)建。
安裝:
virtualenv --no-site-packages env . env/bin/activate pip install cyclone-sse
客戶(hù)端使用:
<!doctype html>
<meta charset=utf-8>
<title>Title</title>
<script>
sse = new EventSource('http://127.0.0.1:8888/?channels=base')
sse.addEventListener('message', function(e) {
console.log("Got message", e.data)
})
/* Some helpful handler to have */
sse.addEventListener('open', function(e) {
console.info("Opened SSE connection")
})
sse.addEventListener('error', function(e) {
console.error("Failed to open SSE connection")
})
</script>評(píng)論
圖片
表情
