Is it possible to allow two clients interact directly without a server?
I am referring to websites, for example is it possible to create a chat between two clients that are on the same website using only javascript
on the client-side.
If not, what's the minimum server-side to make a chat work between active clients on a website? (eg: one PHP
file and no database) ?
My idea:
Storing the conversation would be easily done using localStorage
on each client, the problem is how to send some data from client1
to client2
without storing anything (or at most that message) in the database. Also, note that "past" conversations should not visible, so no storage needed for that.
Note that I don't want any nodeJS or websocket solutions, I want something as simple as possible. So, what's the minimum code
and files
to make a chat between online users?
PCs do not need a server to work as the computing resources are present locally and they are highly customizable by the end user which makes them vulnerable to security risks. Thin clients are used exclusively to access remote resources on a distant server, using only a browser.
Supporting Multiple Clients However, multiple client requests can come into the same port and, consequently, into the same ServerSocket . Client connection requests are queued at the port, so the server must accept the connections sequentially.
The server can be iterative, i.e. it iterates through each client and serves one request at a time. Alternatively, a server can handle multiple clients at the same time in parallel, and this type of a server is called a concurrent server.
Client-side means that the processing takes place on the user's computer. It requires browsers to run the scripts on the client machine without involving any processing on the server. Server-side means that the processing takes place on a web server.
The WebRTC APIs will allow JavaScript to initiate a direct browser-to-browser connection, but a server is still required to serve the page and coordinate session initiation.
The APIs are still rapidly evolving and only available in bleeding-edge browsers, so it's not yet ready for real production use.
However—to be honest—for what you're trying to do, the easiest option is Node and socket.io:
var http=require('http'), express=require('express'), sio = require('socket.io')
, app=express(), srv = http.createServer(app);
app.use(express.static(__dirname+'/static'));
sio.listen(srv);
srv.listen(80);
...and now you have a working websockets server in 5 lines. Put all your client-side stuff in the static folder and you're good to go.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With