File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Connecting to a router

 
ahmed abobakr
Greenhorn
Posts: 3
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi
I want to make a program to connect to a router using Http protocol or Telnet protocol.
I tried running a command prompt on my PC and connecting to the router using telnet commands i used the Process class but i failed

Thank you in advance
 
Rob Spoor
Sheriff
Pie
Posts: 20372
44
Chrome Eclipse IDE Java Windows
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch!

java telnet leads to several Telnet libraries. Surprisingly, Apache Commons Net isn't found on the first two pages, so I thought I'd mention it explicitly.

HTTP is probably going to be more difficult as it will certainly involve a bit more complex requests. HttpClient can be a great help.
 
ahmed abobakr
Greenhorn
Posts: 3
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thank you Rob Spoor


how can i send multiple commands to command prompt?

I tried this code. what the error here?

this program didn't have syntax errors.

 
Rob Spoor
Sheriff
Pie
Posts: 20372
44
Chrome Eclipse IDE Java Windows
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please don't use such a large font. I've had to remove the formatting on both of your posts already. Also, UseCodeTags from now on. See how much easier your code is to read.

Why didn't you use a Telnet library like I suggested?
 
Paul Clapham
Sheriff
Pie
Posts: 20171
25
MySQL Database
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is the command-line Telnet client on your system really called "telent"?
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24204
34
Chrome Eclipse IDE Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The Windows telnet client is a GUI client that doesn't take commands on the command line; something tells me he's just using that stock client, anyway.
 
Ulf Dittmer
Rancher
Pie
Posts: 42966
73
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Does the router really accept Telnet requests?

One issue to be aware of is Don't println to a Socket, which the code is doing by using readLine.
 
Rob Spoor
Sheriff
Pie
Posts: 20372
44
Chrome Eclipse IDE Java Windows
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There's a slight difference. readLine is able to handle \r, \n and \r\n as line breaks. It did (does?) have a bug that if the stream ends with a \r without a \n after it, readLine would block.
 
ahmed abobakr
Greenhorn
Posts: 3
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you for helping me

I think i found the solution to my problem here


but i don't know how can i press the carriage return?
 
Rob Spoor
Sheriff
Pie
Posts: 20372
44
Chrome Eclipse IDE Java Windows
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A carriage return is just the character '\r'. You can include that in Strings as you would any other character.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic