Note that there are some explanatory texts on larger screens.

plurals
  1. POTrying to send telnet commands to a server
    primarykey
    data
    text
    <p>I'm trying to connect to a telnet server (running NetLinx by AMX, in case it matters) and send it a few commands as if I opened Terminal and did "telnet (address)" and started typing commands. I can receive messages but can't send them using this code I found from a tutorial at <a href="http://www.raywenderlich.com/3932/how-to-create-a-socket-based-iphone-app-and-server" rel="nofollow">http://www.raywenderlich.com/3932/how-to-create-a-socket-based-iphone-app-and-server</a>:</p> <pre><code>- (void)sendMessage: (NSString*) message{ //called when the user interacts with UISwitches, is supposed to send message to server NSData *data = [[NSData alloc] initWithData:[message dataUsingEncoding:NSASCIIStringEncoding]]; //is ASCIIStringEncoding what I want? [outputStream write:[data bytes] maxLength:[data length]]; NSLog(@"Sent message to server: %@", message); } - (void)initNetworkCommunication { //called in viewDidLoad of the view controller CFReadStreamRef readStream; CFWriteStreamRef writeStream; CFStreamCreatePairWithSocketToHost(NULL, (CFStringRef)@"192.168.1.90", 23, &amp;readStream, &amp;writeStream); //192.168.1.90 is the server address, 23 is standard telnet port inputStream = (__bridge NSInputStream *)readStream; outputStream = (__bridge NSOutputStream *)writeStream; [inputStream setDelegate:self]; [outputStream setDelegate:self]; [inputStream scheduleInRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode]; [outputStream scheduleInRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode]; [inputStream open]; [outputStream open]; } </code></pre> <p>It appears to send some kind of message to the server <em>but maybe in the wrong format</em>. My guess is that it's a string formatting problem. Is ASCII what I want to use for telnet? If I take the message it prints when it sends a command and paste that right into Terminal with telnet running, the server receives and processes the command normally.</p> <p>Here is an example command that I'm trying to send: SEND_STRING dvJAND,"'#AUX2=0',$0D"</p> <p>Another mystery is that, reading the input stream and printing, I see this when the above is sent:</p> <pre><code>2013-08-20 00:20:23.791 [7548:907] server said: S 2013-08-20 00:20:23.793 [7548:907] server said: END_STRING dvJAND,"'#AUX 2013-08-20 00:20:23.795 [7548:907] server said: 2=0',$0D" </code></pre> <p>But when I type that command in Terminal, the server does not respond at all and does its job as it should.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload