I am writing a server application that accepts TCP connections from different programs/protocols but I need to pass additional information to my server. I was thinking of passing this information through the subdomain being used. In other words, when connecting to my server, using an address such as somedata.example.com
where somedata
will be the extra information I need and my DNS will point *.example.com
to my server. Would it be possible to fetch the domain/subdomain that the client used to connect to my server?
Code samples are welcome and in Go would be even better.
Thank you.
A TCP connection is conceptually just a stream of bytes in each direction. There is no single way that a hostname with subdomain would be communicated. Most protocols have their own way of communicating that if they need it. Examples:
HOST
header.If you are using some standard protocol, you should use their built-in metadata facilities.
If you are building your own custom binary protocol (I wouldn't if I could avoid it), you may consider adding some header info in some format. Perhaps a standardized header of length|desired-service-name|other-data
would be sufficient. If the client sends something like that at the start of a new connection, the server can read it, and dispatch the connection appropriately.