Best jQuery/Java PHP solution for localhost server - client live chat - javascript

I have Apache server with PHP and associated local client PCs in my private network. Can anybody suggest the best chat solution to communicate between client PCs and a server? I am looking for an Ajax/Java solution, like the chat support inside GMail.

Did you consider the XMPP service from google app engine for java?
http://code.google.com/appengine/docs/java/xmpp/
It has very good integration obviously with the rest of google apis and the server can be hosted for free if you're under the quota, or running it on localserver using jetty

You can make use of JQuery / PHP Chat which is free and can be integarted into sites.

Can't do it with Apache. Chat is usually done through a technique called Comet, which is not supported by Apache, AFAIK. GMail uses this technique.
Another, less efficient possibility is using polling strategy, which involves a lot of extraneous server-client communication.

Related

Peer-to-peer Javascript & something

I'm looking for a method to connect client(web browser) to server(without external IP) using p2p.
As client-side language i would like to use javascript.
I was reading about WebRTC Peer-to-peer but i don't know if it only works with two clients(javascript) or if i can use some other language ( PHP, Python, Node.js ).
I know about signaling, STUN and TURN servers. I have server with external IP address so it won't be a problem.
My question is what programming language can i use on the server?
Actualy you can avoid other languages if you will use Kurento media server. It have javascript like native. And it frendly desiged to use it with Node.js backend.
Also Janus-Gateawey have commodious JavaScript API and allows build backend on any language you want. Managing all webRTC things happens on client side. That very cose if you understand webRTC and JS at least on basical level.
For control webRTC from back side on python you can use aiortc library
If you need to send/receive only text data then socket.io with e.g. python-socket.io (on server side) is that what you need
I added to Andrey Suglobov's answer: The client does not receive the WebRTC packets from the server because it doesn't have an external IP. In order to solve this problem, you have to configure it to communicate via the TURN server in the middle.
[WebRTC server] ↔ [TURN] ↔ [NAT] ↔ [client]
Generally, the client uses JavaScript because it's a browser. But WebRTC is a specification that supports P2P on the web. If supporting this specification, it does not matter what programming language you use.
Thank you.
Probably found an answer.
I can use javascript server side in node.js

Cross-Browser Communication

I am designing a website that requires a host and client websites. The host will set something up (a session), and the clients will connect to that host using an ID specific to that session.
I have considered how I will facilitate that communication, and initially I was going to have both the clients and the host periodically query and update a database which holds the current states of all clients and the host to communicate new options and changes - but then I wondered if it is possible, using javascript [or something], for them to connect and communicate directly?
The communication would be very simple messages - single strings to communicate current state and stuff like that.
Im pretty proficient in javascript/html/css, but am happy to learn if there is something that would do a better job of setting this up.
Thanks!
Alex
You could try httprelay.io, requires no additional libraries and can be used for simple http client to client communication.
You're looking for WebRTC, which is the de facto and recommended way of doing peer-to-peer connections through the web with pure Javascript:
WebRTC (Web Real-Time Communication) is an API definition drafted by the World Wide Web Consortium (W3C) that supports browser-to-browser applications for voice calling, video chat, and P2P file sharing without the need of either internal or external plugins.
And yes, before you ask, simple messages can be exchanged as well.
Here is the Mozilla reference explaining WebRTC.
Here is a nice simple tutorial to get you started with the code.
Here is a peer-to-peer chat room with video capabilities built using pure WebRTC as a demo.
Prior to WebRTC, there was no satisfactory decentralised way of doing this.
As the comments indicate, Websockets would have been the right idea if you were going with a centralised system - they facilitate real-time communication between clients and a central host.
Decentralised systems, however, must be implemented using WebRTC - this is the only option on the cards.

What role does Socket.IO have with Node.js

I'm fairly new to the world of JS and its abundance of libraries. I'm looking to get into a project that involves network communication (sockets) between clients and a server. In a world with tons of libraries, I cannot make a decision as to which to use. I'm looking for something that will bring efficiency and stability.
I've been told that Node.js is like the middleman between you, as the developer, and Socket.IO. I've been told it's a huge framework that you may not use at least half of. I've been told that to maximize efficiency, you're better off using Socket.IO to make your own functionalities. I've done some research on my own and found that Socket.IO NEEDS Node.js and Node.js DOESN'T NEED Socket.IO. Which is completely opposite of what I was told. Then I find that most developers use both Socket.IO and Node.js at the same time?
Like I said, I'm fairly new, but I cannot find the right resources that would help me accomplish a websocket communication between a client and a server with maximum efficiency, or at least explain the difference between Socket.IO and Node.js. If anyone here could, please let me know! I would greatly appreciate it.
node.js is a general purpose javascript-based run-time environment (somewhat similar to other language runtimes like python in scope). You can create apps in it that don't even use the network. It is often used as a web server for created web apps and has a great set of tools and rich library of add-ons for doing so. It does not need socket.io.
socket.io is a specific library to enable web-socket-like communication between a client and a server (e.g. a chat room app is the canonical example). The server side of socket.io assumes a javascript run-time (because it's written in javascript) so that generally means node.js (though I'm not sure if a different JS runtime could perhaps be substituted).
You can think of node.js like the platform and socket.io like a specific tool to do a specific job that runs on that platform. You would use socket.io (on top of node.js) if you needed web socket connectivity between client and server.
You would use only node.js if you need any of the other things node is good at, but did not need websocket connectivity.
websockets themselves can be programmed on the server side without socket.io and without node.js. They could be programmed in strait C++ or in Java. But socket.io (running in node) provides a very easy way to set them up because the socket.io library covers both client and server in one library and one API and it's all in the same language (javascript). Look at the chat room app example on the socket.io site and you will be unlikely to find any other solution that can accomplish that in as few lines of code as it does and with the same interface on client and server.
If you were only setting up a websocket server (no web server or web app of any kind), you could still use node and socket.io and use it just for the websocket server and it would still be quite efficient. While node is capable of doing lots of other things, if you don't configure and install all those other things, they aren't costing you anything - they are just unused capabilities that aren't running.
I should add that one other thing the socket.io library does is it handles an auto-negotiation between client and server to find the best channel for the client and server to communicate on. If websockets are available, then socket.io will likely use them, but if web sockets are not available, socket.io has alternate methods that will work (even in older browsers). That functionality comes for free in socket.io without you even doing anything.
In case this isn't completely clear to you, websockets are typically used to provide real-time communication between client and server. While clients can ask for data from a server at any time with an ajax call or a web page request, what websockets allow is a two way real-time communication between client and server and the biggest advantage of websockets is that a server can send a client real-time data at any time while they are connected.
For example, I have a web page that receives real-time data from my server anytime the web page is open. The web page is served over the typical node.js web server installation, but the real-time data is sent from server to client over a websocket connection.
In addition, if there's a chatty conversation happening between client and server, websockets can be much more efficient than a series of ajax calls because with a websocket, a connection is opened once and used repeatedly whereas with ajax, each successive ajax call is like a new connection.
Node.js is a runtime environment. It's a javascript engine with a standard library built around asynchronous I/O. It plays the same role that Java, Python, Ruby, .NET, etc., play for many other web applications.
I've been told it's a huge framework that you may not use at least half of.
It might be true that most people never use most of the standard library, but I wouldn't think it's more true of Node.js than other runtimes. "Framework" isn't an accurate word to describe it.
I've been told that to maximize efficiency, you're better off using Socket.IO to make your own functionalities.
Whoever told you that was mistaken, or meant that to maximize efficiency, you're better off using [Node.js and] Socket.IO [instead of other solutions]. Many other non-Node.js solutions require a single thread or process per connection, which limits the number of simultaneous connections a server can handle. Node.js is built around asynchronous I/O which is better for keeping many connections open at once, and Socket.IO is a library for Node.js for using WebSockets.
TL;DR: Socket.IO can fire events in realtime between your client and server, so there is no need for you to reload the page to notice something changing. This can be used for "live" applications like collaborative drawing, live chats, online games and more!

Communication with javascript and localhost

I have a JavaScript code running on internet browser and in the same machine in local host is running a python code.
I need to find a way to communicate between them.
Socket client-server is not possible because JavaScript don´t support sockets.
How to Use Sockets in JavaScript\HTML?: "There is no facility to use general-purpose sockets in JS or HTML. It would be a security disaster, for one."
And communication through server not interest me. I need a direct communication on localhost.
Is there any way to communicate with JavaScript and localhost without sockets?
No, by the definition JavaScript cannot use TCP/IP sockets because that would be super super big security hole in the web security model.
You can use
HTTP requests (AJAX)
WebSockets
WebRTC
... to communicate with localhost. The easiest solution is to spin up a SimpleHTTPServer and then make JavaScript AJAX requests against it.
Please note that these communications might not work with HTML files opened file:// and you might need to use a local dev server.
httprelay.io requires no additional libraries and can be used for simple http client to client communication. In your case on browser side use AJAX calls and on Python side use any HTTP client.

Connecting to a remote jabber server with a javascript chat client (jsjac)

This is more of a conceptual question.
I'm trying to create a Javascript jabber client that can be installed on any arbitrary page (on x.com and y.com), and I'd like this client to be able to communicate with a remote jabber server (chatserver.com).
According to the readme of one javascript client I'm lookign at (jsjac), it is an inherent limitation of javascript that it can't communicate with a remote server due to cross site issues.
I'd appreciate hearing from anyone about how to overcome this hurdle. A pointer to an example would be extremely helpful.
[Update] I'm assuming here that I have no control over x.com and y.com, the client servers. The folks at Hab.la seem to have pulled this off, not sure how.
The simplest way around this is to proxy the requests from the JavaScript client to the remote server, via the server that hosts the client.
Apache's mod_proxy extension handles this fine.

Categories

Resources