Multiple connections on the same C ++ port

I need to accept multiple connections to the same port. I use socket in C ++, I want to do something like SSH. I can make ssh user @machine "ls -lathrR /" and run another command on the same computer, even if the first one is still running.

How can i do this?

Thank.

+5
source share
3 answers

What you want is a multi-threaded socket server.

To do this, you need a main thread that opens the socket for listening (and waits for incoming client connections). This should go into the while loop.

, , accept() , , .

, .

, , ( ).

. , bind(), listen() accept() .

+10

::listen() ::accept().

. (, ), ::accept(), , .

, , ::accept(), - .

+1

, , , , .

, ssh. / ssh, , , , .

Sshd (the ssh daemon) runs on the server and is a multi-threaded socket server (see fduff answer). This is the only program that listens on port 22 and processes all incoming ssh connections.

0
source

All Articles