Hi,

I have to connect to telnet server and post the XML to the server. In return I need to get Response back.

I dont need to provide login and password.

if i connect to telnet using command prompt of windows and paste XML there, it gives back xml to me as response .. thats fine.

if I use Perl program for that, thats also fine. Bit when I try connecting through java and post XML I am not getting anythng back.

Always getting

java.net.SocketTimeoutException: Read timed out
at java.net.SocketInputStream.socketRead0(Native Method)

My java program is like this.


<code>
package com.ebay.securityswat.openredirect;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintStream;
import java.net.SocketException;


import org.apache.commons.net.SocketClient;
import org.apache.commons.net.SocketFactory;
import org.apache.commons.net.telnet.TelnetClient;

public class TelnetUtil {

private static String REQ_XML = "" ;

private static String HOST_NAME= "server" ;
private static int PORT = <port> ;
public static void main(String[] s){
TelnetClient telnet = new TelnetClient();
try {
telnet.setDefaultTimeout(30000) ;
telnet.connect(HOST_NAME, PORT) ;
System.out.println("Connected ..........") ;
InputStream in = telnet.getInputStream();
OutputStream out = telnet.getOutputStream();

int remotePort = telnet.getRemotePort();
System.out.println("the port is: " + remotePort);

String remoteHostString = telnet.getRemoteAddress().toString();
System.out.println("The IP string is: " + remoteHostString);
// PrintStream out = new PrintStream( telnet.getOutputStream() );

byte[] bytes = getXML().getBytes() ;


out.write(bytes) ;

try {
Thread.sleep(5);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
byte[] buff = new byte[1024];
while (true) {
System.out.println(in.available()) ;
int readBytes = in.read() ;
if(readBytes > 0) {
System.out.print(new String(buff, 0, readBytes));
}
if (in.available() == 0) {
break ;
}

}

telnet.disconnect();
} catch (SocketException e) {
// TODO Auto-generated catch block
try {
telnet.disconnect();
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
try {
telnet.disconnect();
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
e.printStackTrace();
}
}


private static String getXML() {

StringBuffer buf = new StringBuffer(" <Request>") ;
buf.append("</Request> ") ;


return buf.toString() ;
}

}

</code>