• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

Not Sure

 
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
(instanceof Sidekick)
Posts: 8791
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Ranch Hand
Posts: 1646
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 1170
Hibernate Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thank you i got it working *smiles*
 
Please enjoy this holographic presentation of our apocalyptic dilemma right after this tiny ad:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic