Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

telnet

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
hi,

I try to make a telnet to an XP host, with a JAVA application but it don't
seem to work fine, when I try with the windows telnet, I got normal
connection:
/*************************/


Welcome to ..........

some text............


are you sure (o/n) :

/*****************************/

but with java application there's no text in my application,

here the source:


/******************************/


import java.io.*;
import java.net.*;


public class TelNet
{

public static void main(String args[])
{
byte[] env;
String mess="";

try
{

Socket esp = new Socket("192.168.0.1", 23);

BufferedReader esplire = new BufferedReader(new InputStreamReader(esp.getInputStream()));
DataOutputStream especrire = new DataOutputStream(esp.getOutputStream());


String lir = esplire.readLine();
while(lir!=null)
{

System.out.println(lir);

lir = esplire.readLine();

};

}
catch(Exception e){System.out.println(e.toString());};

}
}


/*******************************/


can some one help me.

thanks.
 
As far as i know this code should run. But there is one situation when this could hang. Instead of reading a line
try to read using a buffer. Because when you use readLine method it blocks until it sees a '\n' character.So try either reading (byte by byte) or (to a byte buffer).
 
hi rajeessh,

you're wright, I try it byte by byte and now it's working fine.

thanx for the help.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top