Results 1 to 1 of 1
Thread: problem with Java and telnet
- 01-30-2008, 03:52 AM #1
Member
- Join Date
- Jan 2008
- Posts
- 1
- Rep Power
- 0
problem with Java and telnet
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>
Similar Threads
-
Java Telnet App Implementation
By mgdesmond13 in forum New To JavaReplies: 1Last Post: 07-28-2008, 01:58 AM -
Problem in java
By saytri in forum New To JavaReplies: 4Last Post: 01-16-2008, 10:09 PM -
Java Telnet App Implementation
By mgdesmond13 in forum Java AppletsReplies: 0Last Post: 12-26-2007, 03:15 PM -
Telnet client Java
By susan in forum NetworkingReplies: 1Last Post: 07-30-2007, 09:59 PM -
JAVA if problem
By toby in forum New To JavaReplies: 2Last Post: 07-25-2007, 07:58 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks