Reputation: 2049
I have to write a load balancer for our custom server, not http. I have gone through lot of articles over internet. Every where its mentioned that load balancer redirects the connection to actual server. But no where is mentioned in how to redirect the connects. Can some body tell how to implement the connection redirection in C ?
Thanks
Upvotes: 0
Views: 928
Reputation: 69
Redirecting connection in this context means creating a proxy between two connections - external (client facing), and internal (server facing). On one end you listen for incoming connections, on other you pick a backend server and redirect traffic from client connection there. In essence you're creating a flow from two ip tuples:
((external ip, external port, external interface) , (internal ip, internal port,internal interface))
The data flow is:
client load balancer server
[c1 sock]<--->[external socket | internal socket]<--->[s1 sock]
Basic operation mode would be:
You can implement it without the usage of sockets, at the network layer, but that requires userspace TCP/IP stack implementaton and ability to read packets directly from network adapter queue.
nginx
can load balance TCP
and UDP
connections. Why not use it instead of reinventing the wheel? It is probably way more tuned and battle tested that your solution will be in a few years.
Upvotes: 1