By using "localhost" you've hardcoded it to only work with the client and server on the same host.
You'll need some way for the user to specify to the Client the hostname for the Server an then use that in the connection to the server.
You probably need something like this:
IPHostEntry ipHostInfo = Dns.Resolve("host.contoso.com");
IPAddress ipAddress = ipHostInfo.AddressList[0];
IPEndPoint remoteEP = new IPEndPoint(ipAddress, port);
from
MSDN: Asynchronous Client Socket Example[
^]