• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Not Sure

 
Andy Rayner
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The way you read responses looks a bit suspicious. What happens if you remove the extra read() after the readline()?
 
Andy Rayner
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1646
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1170
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thank you i got it working *smiles*
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic