Solved

simple Telnet app, empty read buffer

Posted on 2010-08-25
19
782 Views
Last Modified: 2013-12-29
I am trying to write a Telnet interface to ICC, the Internet Chess Club.  Attached is the code I have so far.  Wireshark shows that when I run this program, the message "Welcome to the INTERNET CHESS CLUB" is sent across the wire, but the read buffer is empty at line 59.  Why is the buffer empty and/or how should I be reading from the socket?
Main.java
0
Comment
Question by:blackfrancis75
  • 8
  • 7
  • 4
19 Comments
 
LVL 86

Expert Comment

by:CEHJ
ID: 33521823
What happens when you use a telnet app to do the same?
0
 
LVL 5

Author Comment

by:blackfrancis75
ID: 33522329

telnet> open chessclub.com
Trying 207.99.83.228...
Connected to chessclub.com.
Escape character is '^]'.
Welcome to the INTERNET CHESS CLUB

web:   www.chessclub.com    email: icc@chessclub.com
phone: 1-412-521-5553

login:
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 33522578
So what gets printed - a solitary right angle bracket?
0
Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

 
LVL 5

Author Comment

by:blackfrancis75
ID: 33522713
yes.  I also checked the buffer (using Eclipse debugger) and it appears to be empty
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 33522959
Configure it to be blocking and you'll probably find it'll read something. If you want non-blocking, you should probably use a Selector
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 33523441
Another consideration is that a telnet stream contains control characters, so will not decode completely as text
0
 
LVL 5

Author Comment

by:blackfrancis75
ID: 33523734
yeah, that's why I checked that the buffer was actually empty using the debugger.

I don't get it though - this is the documented nio.* way to open a socketchannel and read from it. I'd like to understand why it doesn't work.
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 33523866
0
 
LVL 92

Accepted Solution

by:
objects earned 500 total points
ID: 33527034
commons net supports telnet out of the box

http://commons.apache.org/net/

no need to reinvent the wheel
0
 
LVL 5

Author Comment

by:blackfrancis75
ID: 33527328
CEHJ: If I run that program with parameters: chessclub.com 23
it hangs at line 52:  
mIn.read(buf);
indefinitely
0
 
LVL 92

Expert Comment

by:objects
ID: 33527350
> Another consideration is that a telnet stream contains control characters, so will not decode completely as text

How would control chars cause it to "not decode completely"?
And how would that cause a read() to block anyway?
0
 
LVL 5

Author Comment

by:blackfrancis75
ID: 33527503
CEHJ: objects really doesn't like you today
0
 
LVL 92

Expert Comment

by:objects
ID: 33527536
his comments are getting a little questionable ;)
0
 
LVL 5

Author Comment

by:blackfrancis75
ID: 33527606
perhaps you can comment on why my code wont work ;).  I looked at commons-net but would prefer to use my own basic implementation, if it can work.
0
 
LVL 92

Expert Comment

by:objects
ID: 33527628
sorry don't have the time available. I only spend a small amount of time on EE these days.
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 33529044
Actually i've tried it with a telnet stream and it behaves weirdly with that too. I can only guess, at this point, that the server could be disallowing automation by screening for 'real' telnet clients.
0
 
LVL 5

Author Comment

by:blackfrancis75
ID: 33549541
Using the example code for the Commons-net telnet works fine.  I wish someone could tell me why my original code doesn't work.
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 33550378
I used commons net telnet too - with weird results
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 33550487
Just tried it again - seemed ok that time. Possibly an intermittent problem..?
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
fibonacci ten numbers 4 46
Desingning Refactoring existing code 2 26
JavaFX TableView not displaying correctly 3 62
ejb mdb examples 1 10
INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:

821 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question