September 3rd, 2003, 11:55 AM
more telnet trouble
This is for the same app that I had a question on a couple weeks ago about function keys, where I'm automatically updating wireless access points. I have that issue solved but I've run up against something else. I'm trying to send a short string (15 characters max) to the access point. Everything else I send is a one character command. For some reason I'm only getting the first character across (I know because it echos what you send). I have tried sending the entire string, but I know telnet really expects individual packets with one character in each packet for input, and so I've also tried looping through and sending each character. Still only get the first character to go. Here's the kicker: if I step through the app in the debugger (borland builder), it works like a charm. I'm not quite sure what the difference is except that maybe there is a speed issue involved (sending them out in the program they're too close together and get mixed up or lost somehow, but tcp is supposed to be more reliable than that). I could just use a timer, but this is already part of another timer call. Any other ideas about how I can make it pause for a moment between sending each packet?
September 3rd, 2003, 12:38 PM
perhaps im stating the obvious here, but how bout a call to sleep() or usleep() ?
September 5th, 2003, 09:19 AM
no good. Not using threads, just a timer. I worked around it by using a couple nested while loops to eat up a few thousand clock cylces between each character, but that's very poor technique and I know it. Any ideas on how to to it better?
September 5th, 2003, 09:41 AM
Huh? Non sequitur. sleep() (and Sleep() for Win32) is available whether you're using threads or not. Just be sure about whether the argument is in seconds (as in Linux) or milliseconds (Win32, even the MinGW port of gcc calls for milliseconds).
BTW to Infamous: thanks for word on usleep for Linux, which takes microseconds. Hadn't heard of it before.
f'lar, if you're working in Windows then you could also look at doing a SetTimer() and then handle the WM_TIMER event.
In Linux, you could call alarm() and then handle the SIGALRM signal.
And at no point would you ever need to use threads.
September 5th, 2003, 11:26 AM
Okay. sleep() wasn't available to me, but Sleep() works great. I made the threads comment because i did some searching and a few results came up relavent to using threads. Should've thought to check case. thanks