Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Topic: NIO Socket and Windows telnet  RSS feed

 
yu mei
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I used NIO to construct a server application, but when I access it via windows telnet(C:\windows\telnet.exe)
every character input will activate the server to deal it. How to avoid it.
I mean that before I click return key, the registerkey has become readable().
 
David Weitzman
Ranch Hand
Posts: 1365
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try typing a few thousand more words per minute .
Seriously, that's non-blocking IO doing its job. Even if your telnet client only sent data after each return, there's no promise from NIO that the stream won't be readable until you get a return. You have to analyze the data stream and the end of the line yourself.
I can point you to some code I wrote once, but the particular architecture you use may affect the pattern you want to use. Also I tried to be an RFC nazi and assume a client won't send a new command until the server responds to the previous command, although I know I've written code that can handle streamlined commands -- I'll let you know if I can the more forgiving version.
The real downside of non-blocking IO is that parsing things asychronously sucks. It's kind of surprising that there isn't a mainstream parser-generator that supports a callback syntax, since at the very least regular expressions can be evaluated one characters at a time. Anyway, good luck.
[ February 17, 2004: Message edited by: David Weitzman ]
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24215
37
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by David Weitzman:

The real downside of non-blocking IO is that parsing things asychronously sucks. It's kind of surprising that there isn't a mainstream parser-generator that supports a callback syntax, since at the very least regular expressions can be evaluated one characters at a time. Anyway, good luck.

SAX works this way, and I bet an NIO-based SAX parser would be really nice. I just finished writing my first SAX-based XML code recently, and once you get used to it, it's actually cleaner than using the iterative DOM style.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!