I was thinking of changing the way I'm doing it.
One way is to have different function one for each kind : HTML5 / Android / heavy client
Or an auth proxy server somewhere else which does the same thing as my TCP Server and regular request on this
It brings some security issues ( one more server, man in the middle ) but it is the easiest way