What you need is a multiplexer for TCP connections. Probably you can use HAProxy (http://www.haproxy.org/) to do what you want, but there are more options. HAProxy is not limited to HTTP connections. For example, I know someone who has used it for SMTP connections. The idea is a follows. You define a HAProxy frontend running on port 6000 that has two rules for dispatching traffic:
frontend frontend_name
bind *:6000
acl first_host hdr(host) -i first.com
acl second_host hdr(host) -i second.com
use_backend first_backend if first_host
use_backend second_backend if second_host
Then you define two backends for each host. You will need three separate ports for frontend and two backends. I have not personally tested it, but the syntax should be more or less OK.
Edit: This will work only for HTTP/HTTPS connections. However, if your protocol includes the server name in a request it might be possible to extract the server name from the request with req.payload function.