eventsource

Is it reliable to use EventSource to get User's online status?

为君一笑 提交于 2019-12-06 00:27:49
I have used an EventSource method to get online status of active users on my website. In this following JavaScript code is inserted in every page var source = new EventSource("set_online.php"); Thus this code is executing set_online.php file continuously. On server side i.e. in set_online.php following code executed $query = "UPDATE my_db SET last_active = '{$current_time}' WHERE id = {$_SESSION["id"]}"; $result = mysqli_query($connection, $query); Now I have two concerns about this: As Database is updating last_active continuously in realtime, will it affect server load? As connection is open

Angular2/typescript and SSE (EventSource)

为君一笑 提交于 2019-12-05 10:27:44
First of all, I`m quite new to ng2 and typescript. What Im trying to accomplish is to implement Server-Sent events in Angular2 component. I have followed the examples mentioned in earlies posts here, but my problem is that the "EventSource" object is unrecognized (red underline, in VS Code). Im not sure if I`m missing some references... My references are: <!-- IE required polyfills, in this exact order --> <script src="node_modules/es6-shim/es6-shim.min.js"></script> <script src="node_modules/systemjs/dist/system-polyfills.js"></script> <script src="node_modules/angular2/es6/dev/src/testing

Web实时通信技术

自古美人都是妖i 提交于 2019-12-01 03:11:48
本周在应用宝前端分享会上分享了Web实时通信技术,分享内容整理如下。 一、传统Web数据更新 传统的Web数据更新,必须要刷新网页才能显示更新的内容。这是浏览器采用的是B/S架构,而B/S架构是基于HTTP协议的。HTTP协议的工作模式就是客户端向服务器发送一个请求,服务器收到请求后返回响应。所以这种工作模式是基于请求显示数据的。 这样的工作方式有其自身的好处,但是也会导致很多问题。在Web应用越来越火的今天,经常会遇到需要服务器主动发送数据到客户端的需求,比如事件推送、Web聊天等。这些需求使用传统的Web数据更新工作模式是无法实现的,因此就需要一项新的技术:Web实时通信技术。 二、短轮询 第一种解决方法思路很简单,既然需要客户端发送请求服务器才能发送数据,那么就可以让客户端不断的向服务器发送数据,这样就能实时的获取服务器端的数据更新了。具体的实现方法很简单,客户端每隔一定时间就发送一个请求到服务器端。下面的图可以清晰的反映出短轮询过程中客户端和服务器的工作流程: 下面看一下实现方法。 在服务器端我们模拟数据的发送,生成1-1000的随机数,当数值小于800的时候模拟没有数据的情况,大于800的时候模拟有数据的情况,并返回数据: <?php $arr = array ( 'title' => '推送!' , 'text' => '推送消息内容' ); $rand = rand(

Creating an RxJS Observable from a (server sent) EventSource

邮差的信 提交于 2019-11-29 22:20:06
问题 I would like to create a RxJs Observable from an EventSource (server sent events). I tried the following: import {Component, OnInit} from 'angular2/core'; import {Subject, Observable} from 'rxjs/Rx'; @Component({ selector: 'my-app', template: `<h1>My second Angular 2 App</h1> <ul> <li *ngFor="#s of someStrings"> a string: {{ s }} </li> </ul> ` }) export class AppComponent implements OnInit { someStrings:string[] = []; ngOnInit() { let eventSource = new EventSource('/interval-sse-observable');

server sent events (eventsource) with standard asp.net mvc causing error

我们两清 提交于 2019-11-27 04:56:43
I am trying my hand at server-sent events, but I cannot get it to work within an MVC project (not WebAPI). I haven't found any good samples online. This is the server-side code I tried (including several failed attempts from various posts): Function GetRows() as ActionResult Dim ret = New HttpResponseMessage ' ret.Content.w ' Return ret Response.ContentType = "text/event-stream" Response.Write("data: " & "aaaa") Dim flag = False If flag Then For i = 0 To 100 Response.Write("data: " & i) Next End If Response.Flush() 'Return Content("Abv") 'Return Content(("data: {0}\n\n" & DateTime.Now.ToString