This week's book giveaway is in the OCAJP 8 forum.
We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line!
See this thread for details.
The moose likes Threads and Synchronization and the fly likes Not Sure Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of OCA Java SE 8 Programmer I Study Guide this week in the OCAJP 8 forum!
JavaRanch » Java Forums » Java » Threads and Synchronization
Bookmark "Not Sure" Watch "Not Sure" New topic

Not Sure

Andy Rayner
Ranch Hand

Joined: Dec 09, 2004
Posts: 36
Hello i have a question which is a bit about threads and a bit about sockets but im not sure which forum to put it in hope this is the right one.

I have these classes


and i have a class for an InputStream and an OutputStream

and finally my output stream

As you can see i am trying to write a client to connect to a telnet server which is a text based game, i get the initial text, but when i put my text in it doesnt reply to me, if i put in some invalid text it replies.

example = Enter your login id:
If i put Andy nothing happens
If i put Andy# it tells me ive entered a wrong id

does anyone know where i am going wrong?

Stan James
(instanceof Sidekick)
Ranch Hand

Joined: Jan 29, 2003
Posts: 8791
The way you read responses looks a bit suspicious. What happens if you remove the extra read() after the readline()?

A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
Andy Rayner
Ranch Hand

Joined: Dec 09, 2004
Posts: 36
I have taken that out and i now have

i dont know what i am doing wrong but i am not getting any response from the server when i type in, it is like the threads hang, are they synchronised properly?
David Harkness
Ranch Hand

Joined: Aug 07, 2003
Posts: 1646
Your InputStream class only reads and sends one line to the server. Since this isn't in a loop, the thread terminates immediately, leaving only the thread that's reading data from the server.

By the way, be careful when naming your classes with the same name as a common Java core class, like Input- and OutputStream. You might want to name these classes ReaderThread and WriterThread, for example.
Mr. C Lamont Gilbert
Ranch Hand

Joined: Oct 05, 2001
Posts: 1170

If you go to there is a program called chessOne which is free for download and the source is there.

It uses a telnet server to connect to You can look at the code and see how to handle the input stream, output streams, and get a bit of info on the threading model of client-server as well. Should be easy to understand .

the sockets is handled basically by 2 classes, IOProcessor and something else I think.
Andy Rayner
Ranch Hand

Joined: Dec 09, 2004
Posts: 36
thank you i got it working *smiles*
I agree. Here's the link:
subject: Not Sure
It's not a secret anymore!