Archived

This topic is now archived and is closed to further replies.

Aggrix

Receiving Telnet Text

Recommended Posts

I made a simple program that checks if someone connects to my comp on port some port using Telnet. If they do, it sends a message to the Telnet window. My question is, how would I receive text from Telnet? Like if the user would type something and hit enter how would I receive what they have typed? I am using WinSock. THanx

Share this post


Link to post
Share on other sites
The return is a character like any other: ''\n''

All you need to do is write a small loop which recv()s some bytes and then prints them literally to stdout.

cu,
Prefect

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Ahh i get ya,
yeah, basically what the guy before said, you''ll have to just receive each character and buffer them until you get sent a ''\n'' newline, then you can look at the string and do whatever you want with it. You''ll also have to check for backspace characters and if you receive one, then delete the last char on the buffer. This is, of course as long as i am remembering correctly that telnet clients send each character as it''s typed in? You might also need to build in an echo, i think some clients rely on the text they''re typing to be echo''d back to them as they''re typing in...

Share this post


Link to post
Share on other sites
I hope you don''t mind that I use your topic for a very simular question.
For the first time I tried to use linux to code a simple listener that recives characters from telnet. This may be a very simple thing but I can''t figure it out. The thing is that when I run telnet on the same computer (I have only tried it on the same) I only get the characters when the client presses enter. The odd thing is that the listener recives one and only one character at a time in a loop until a ''\n'' is recived. But the characters doesn''t get printed on the listener side until enter is pressed on the other side. Did all that make seens? (of course I have cout in side the loop)

Hope someone could explain this to me. Thanks.

Share this post


Link to post
Share on other sites
cout buffers out but, i think there is a way to flush() it. if not use printf() or putc(). also beforewarned some telnet clients buffer output till enter is pressed to help keep transmissions faster since all editing of the line can be done local to the client and the server only gets the final output. you dont have to worry or change anything, just a little more information in case you run into someone using a telnet client that does this.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
This isn''t an exact technical description, but just from my observation, cout normally won''t output anything to the screen until it either encouters the ''\n'' character, or the program ends. As noted anove you can use cout.flush() to force the current buffered output to be sent to the screen.

Share this post


Link to post
Share on other sites