can I have different websockets input in the same server - output in different clients

Let me clarify the title of the question.

On the client side I have two different html files, client1.html and client2.html. They send data via websockets to the same server.js file, in node.js.

On the server side, if the data came from client1.html I want to perform a query and send the outcome to the client1.html. On the same server, if the data came from client2.html I want to perform another query and send to the client2.html the message "Data Saved".

I guess, I have to create two different functios in the server.js. OK.

But, my problem is, on the server side, how to tell, which data came from which client? Also, how the server can send back the right message to the right client?

Thanks in advance

You have to register your clients. For example if a user A is on page client1.html then you send a message (via websockets) for example JSON (or any other format you like):

{ "user": "A", "page": "client1.html" }

Now on the server side you just mark that this user/connection came from client1.html. You can add for example a custom property:

conn.source = "client1.html";

Or any other way (depending for example on framework).

You might even use a handshake for this (instead of sending JSON): when connecting to the server do for example (on the client side):

var ws = new WebSocket("ws://myserver/client1.html");

Now you just have to do the same in handshake code (client1.html is a part of URL now in handshake).

As for other question: on the server side you keep lists of all users for client1.html, client2.html, etc. The rest is obvious: you loop over a target list and send a notification to those users.

Of course there are many small details here. Like you have to remove users from lists if a connection is dead (thus you need a background task to check whether a connection is alive), etc. But that's the general idea.