Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 01-30-2008, 04:52 AM
Member
 
Join Date: Jan 2008
Posts: 1
artofabhi is on a distinguished road
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>
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Java Telnet App Implementation mgdesmond13 New To Java 1 07-28-2008 02:58 AM
Problem in java saytri New To Java 4 01-16-2008 11:09 PM
Java Telnet App Implementation mgdesmond13 Java Applets 0 12-26-2007 04:15 PM
Telnet client Java susan Networking 1 07-30-2007 10:59 PM
JAVA if problem toby New To Java 2 07-25-2007 08:58 PM


All times are GMT +3. The time now is 03:12 PM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org