Suppose I create a very simple socket connection, how can one programatically:
You will find these links usefull, since the question doesn't provide a language, here's for the most common ones.
Socket Programming in C
Socket Programming in C#
Socket Programming in Java
Socket Programming in Python
So, use any of these links and go to the languge you are using. Find the function for getting your host address or ip address and use the Bind method for the appropriet language. This will force the application to bind to that interface.