@Yosuva : If you are facing issue with telnet , then you can have a try with ssh.
Before doing any code related try
- Open mac and system properties and tick remote login
- open windows machine and install openssh and set path
- open cmd and try ssh root@hostIpaddress
IF you are able to do that then convert you code to sshClient. Take a help of below link