I am writing a multithreaded server application, in C (linux), that must listen to 2 different port numbers, say listen to port no 3000 and 4000, for different clients connecting to it to serve different functionality (actual function is executed by a worker thread, main thread runs indefinitely and spawns of new workers upon new connections). I am not sure if select would work here as we can have multiple socket connections but all associated with same port number. I tried sequentially binding to sock_1 and sock_2. When I run client_1, everything works as expected. But, when I run client_2, I get an error on connect() from client side. If select() can be used here, please let me know how to do it. Any help much appreciated ! Thanks !
(P.S sock_1 refers to port no 3000 and sock_2 refers to port no 4000, client_1 refers to client thats seeking service from port 3000 and client_2 refers to client seeking service from same server from port no 4000)
You have totally misunderstood socket and port, these two are different things.
A port can have multiple sockets. but you can bind your listing socket(passive socket) to only a single port.
Before going any further read this
If you want that your application listen on two different ports, have you bind two different sockets with it.
For a Quick reference a select in single process can only have upto 1024 socket descriptors.
So if you are using a single process model then a select can only handle 1024 connections.
Also read C10k problem see what suits your need.