aspose file tools*
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 Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » Threads and Synchronization
Bookmark "Not Sure" Watch "Not Sure" New topic
Author

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

Model



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?

regards
andy
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 rigidsoftware.com there is a program called chessOne which is free for download and the source is there.

It uses a telnet server to connect to freechess.org. 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: http://aspose.com/file-tools
 
subject: Not Sure
 
Similar Threads
a big problem
making Thread of methods
Server sending data to Clients Randomly
Socket exception
Mimic Browser Httprequests & posts