Building a chat system with Javascript [closed]

≡放荡痞女 提交于 2019-12-06 11:19:59
Raynos

Yes/No.

You can implement a chat system using JavaScript and HTML alone using one of three things

  • P2P cross browser communication (only works in opera)
  • CORS/JSONP remote server to relay chat messages (requires a third party service)
  • your own server to relay chat messages

Note that chat messages can be stored locally so you only need a relax server. However if you want to recieve messages whilst "offline" you would either need a clever P2P storage mechanism or messages stored in a server.

Also note that your server can run JavaScript (using node.js)

Also note that a chat system without CSS is a bad user experience.

This is perfectly possible, and quite simple by the way!

Use Socket.io together with node.js... the Socket.io demo is, not surprisingly, a chat: http://socket.io/get-started/chat/

Socket.io has a client library that makes it very easy to add real-time communication to your site. Follow the previous Getting started to learn more.

All that's left now is how to store the messages on the server. You have a LOT of different ways to do that... Microsoft has an example created using their very fast Table Storage (a kind of NoSQL database): http://azure.microsoft.com/en-us/documentation/articles/storage-nodejs-use-table-storage-web-site/

There are some node.js packages to connect with popular relational databases: https://www.npmjs.org/package/mssql (Microsoft SQL Server), http://azure.microsoft.com/en-us/documentation/articles/sql-database-nodejs-how-to-use/ (Sql Database in Microsoft AZURE), http://nodejsdb.org/ (MySQL and Drizzle), and many others. I didn't use any of them yet!

As for merits and demerits, I really believe that node.js + socket.io is perhaps the BEST technology one could use for real-time communication, which includes a chat server and client. But for chatting you should also consider XMPP which is a somewhat standard protocol of sorts for chatting, and there are already free and open servers and clients, and there's also some good XMPP servers for node.js.

Keep in mind that Google stopped using XMPP in favor of a custom implementation, and Whatsapp uses a customized XMPP server, so it is not that uncommon to deviate from the "norm"... Use what is best for your problem. If your requirement is a simple chat client and server, perhaps it is best to write the chat protocol yourself with only the needed features (that's what I did, since my chatting requirements were very specific, yet simple... it would be harder to configure/customize a XMPP server to do what I needed).

As for demerits I really don't think there are any if you use the proper tools. You can build a HTML 5 chat client as incredible as any desktop client out there with current browsers.

it's impossible. here is the simple chat application. It will help you. http://net.tutsplus.com/tutorials/javascript-ajax/how-to-create-a-simple-web-based-chat-application/

It's doesn't actually answer your question, but take a look at www.chatjs.net. it may help you as well.

You can use Virtual World Framework to implement a system like so:

http://www.virtualworldframework.com/web/example/demochat

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!