I want to create a private message system using NodeJS and websockets. I was wondering what the best way is to create such system.
Is it better to create 1 nodeJS server and bind listen-event for each user, or should I create a unique port/server for each conversation between 2 users. i.e.
conversation 1 (user1 & user2): port 8080
conversation 2 (user2 & user3): port 8081
conversation 3 (user1 & user3): port 8082
Is it better to create 1 nodeJS server and bind listen-event for each user, or should I create a unique port/server for each conversation between 2 users. i.e.
Neither.
You can easily create a private conversation between two users with one server listening on one port and allowing users to connect to the server and then identify which other user they want to have a private conversation with.
You can see some pieces of what you're asking about in this socket.io demo chat server.
Here's a more detailed description for how this works:
Note: It is a requirement of pretty much any scheme that you have both user authentication and you have a user identifier. You will then also have to surface that in a user interface so that a given user can identify which currently connected user they wish to communicate with.