The scenario is pretty simple:
Using TCP/IP I have a client which connects to me (server) I want to forward the data the socket sends me to another socket which I opened and the data I received from that socket backwards.Just like a proxy.
Right now I have 1 thread one who listens from incoming connection and spawns another 2 when a connection from the client is established. I must use a mechanism for communicating in the threads.
Is there anything simpler which I can use to act as a TCP/IP proxy ? Does Linux have socket forwarding or some kind of mechanism ?
Advertisement
Answer
You don’t need threads. Take a look at select()
, epoll()
or kqueue()
in order to manage multiple sockets without any thread (if you’re on Windows, it’s the completion port
).
This is an example of a select-based server, it will be a good start.