简体   繁体   English

将通知推送到浏览器窗口

[英]Push notifications to browser window

I am hosting my own server on my private Windows 8 machine. 我将自己的服务器托管在专用Windows 8计算机上。

I am looking to develop an online chat application as a part of a larger website i am developing. 我希望开发一个在线聊天应用程序,作为我正在开发的更大网站的一部分。 A simple Google search suggested using AJAX requests and a server-side chat HTML page, with the browser sending requests to fetch the page every so often via a Javascript loop. 建议使用AJAX请求和服务器端聊天HTML页面进行简单的Google搜索,然后浏览器会通过Javascript循环发送请求以获取页面。 I didn't really like this approach, and was looking for something a little more "modern". 我真的不喜欢这种方法,并且正在寻找一些“现代”的东西。 Normal chat programs use push notifications, so i figured i should be able, too. 普通的聊天程序使用推送通知,所以我认为我也应该能够。 Maybe something like this would work: 也许这样的事情会工作:

  • Server-side program/script listens on a port for incoming requests. 服务器端程序/脚本在端口上侦听传入的请求。
  • Browser sends an AJAX request to the server on the specified port whenever a user types in a message. 每当用户键入消息时,浏览器都会在指定端口上向服务器发送AJAX请求。
  • Server-side program/script records the message in a MySQL database or file. 服务器端程序/脚本将消息记录在MySQL数据库或文件中。
  • Server sends a ... something ... to the browser window. 服务器向浏览器窗口发送一个消息。
  • Client web page receives the something from the server (via JS?) and formats/displays the message appropriately. 客户端网页从服务器(通过JS?)接收消息,并适当地格式化/显示消息。

I have only had experience with static pages (HTML/CSS/JS) in the past, and have just recently dabbled in PHP. 我过去只接触过静态页面(HTML / CSS / JS),最近才涉猎PHP。 So ... i naturally have some questions. 所以...我自然有一些问题。

  • What port should i use? 我应该使用哪个端口? Do i just pick a number and stick with it, or are there specific numbers that are meant for specific things? 我只是选择一个数字并坚持使用,还是有用于特定事物的特定数字?
  • Can i write the server-side program in C/C++? 我可以用C / C ++编写服务器端程序吗? I am pretty sure i could download and learn to use libraries that would interact with MySQL databases and send requests. 我非常确定我可以下载并学习使用与MySQL数据库交互并发送请求的库。 Should i use another language? 我应该使用其他语言吗? Would it be easier in a scripting language like Python? 使用像Python这样的脚本语言会更容易吗?
  • The big one: How on earth am i going to receive the request on the client side? 最重要的一点:我到底将如何在客户端接收请求? I don't know of any sort of JavaScript push notification API. 我不知道任何JavaScript推送通知API。

I tried using NodeJS, but i have no idea if that would be suitable for my needs, or if there are better alternatives. 我尝试使用NodeJS,但我不知道这是否适合我的需求,或者是否有更好的选择。 To be honest i don't really even know what it is... 老实说,我什至不知道那是什么...

I would say stick with Node combined with socket.io. 我会说坚持使用Node与socket.io相结合。 You can create a push notification application pretty quickly with these. 您可以使用这些快速创建推送通知应用程序。

Check out the socket.io site: http://socket.io 查看socket.io网站: http ://socket.io

Also, I really should have mentioned Sails. 另外,我真的应该提到Sails。 It's an MVC framework for Node that has socketio built right in. 这是Node的MVC框架,内置了socketio。

http://sailsjs.org/#/ http://sailsjs.org/#/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM