Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Allow two clients interact without server

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?

like image 440
XCS Avatar asked Mar 21 '13 15:03

XCS


People also ask

Can a client work without a server?

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.

Can two clients connected to same port?

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.

Which server handles multiple clients at the same time?

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.

What is client server-side interaction?

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.


1 Answers

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.

like image 118
josh3736 Avatar answered Oct 05 '22 14:10

josh3736