0

The situation is I spin up a Rachet socket server with a shell script like this

$webSocketServer = new WsServer(new Chat());
$originCheck = new OriginCheck($webSocketServer, ['xdomain.com']);

$server = IoServer::factory(
    new HttpServer($originCheck), 8080);
$server->run();

I have already a client side builtup that use AngularJs Websocket service. Till now its going fine.

Question As of now you can see i just manually run this script in terminal that run this server on port 8080.

But what i am trying to achieve is to create a user generated chatrooms.

In a sense that when user visits xdomain.com. He has a option to create a chat room. He clicks the button and it will hit my server. My server should create a new socket server for that user and give him a secret code/link. The user will send this code to his friends.

When their friends visit xdomain.com they will see two options

1 - Join room (they has to provide the code that they got from his friend) 2 - Create a chatroom (This will function the same way i described above)

Now I am not sure about this architecture. Is it good / bad / possible / impossible.

How many connection one Rachet Socket server will able to handle?

For every request to create a chatroom, my script will create a new Rachet Socket Server on a new available random port. Lets assume this site becomes very popular, will my vps able to open so many socket server on different ports? Do i have so many ports avaiable ?

Also,

On a single chatroom (Socker Server), Will users be able to transfer media files or its just text message that a Socket Server can receive?

Thanks

Raheel
  • 8,716
  • 9
  • 60
  • 102

1 Answers1

1

Create socket server for new room - it is bad idea. First of all, max port count is 65535 + limit on files descriptors (cat /proc/sys/fs/file-max)

Socket server can keep many connection (for example my socket-server can keep in normal day 12000)

My opinion:

  1. Create a socket-server (if you need many connections, you can create 2-3 socket-servers)
  2. Create balancer (It can return socker-server port for client)
  3. Install a ZMQ
  4. Receive new message from ZMQ and push to client.
  5. Client is writing message, this message is pushing to ZMQ, and socket-server is receiving message and pushing one to client.
  6. If you need push files - push it on http server, and write message about ones in ZMQ
Maxim Tkach
  • 1,607
  • 12
  • 23