Remote Machine Connnection using IP and port

Hi,

I want to connect to a remote server on a specific port number.

There is a specific machine through which i have to connect with remote machine.This machine has unix platform.

On a command window ,If a command,
telnet ipaddress portnumber

It will connect with the server,
now if any command is given then it gives response string.

I want to automate this process by programming.

using java i want to establish a connection to the remote server on specific port. and then required commands will be given and response will be accepted.

the various commands are in specific format with differant parameters.

It will respond also in specific format with message status. ex. 400 means success etc.

If you find the solution to this problem then please send.

Thank you all.

Mehul