Re: Telnet Networking Example
Re: Telnet Networking Example
- Subject: Re: Telnet Networking Example
- From: DerNalia <email@hidden>
- Date: Thu, 23 Jul 2009 16:31:52 -0500
Thanks all, for your help. I think I'm starting to understand what is
kind of going on. The example code helped a lot, however, now I am not
correctly receiving from the server:
This is what I'm using to send to the server:
if (oStream)
{
NSData * dataToSend = [command
dataUsingEncoding:NSUTF8StringEncoding];
int remainingToWrite = [dataToSend length];
void * marker = (void *)[dataToSend bytes];
while (0 < remainingToWrite) {
int actuallyWritten = 0;
actuallyWritten = [oStream write:marker
maxLength:remainingToWrite];
remainingToWrite -= actuallyWritten;
marker += actuallyWritten;
}
}
It was in the sample code, and I'm having a bit of trouble. What is
the test for oStream mean? what is it's purpose?
I changed if (oStream) to if(TRUE) and it went into an infinite loop.
oStream has already been opened, retained, delgate set to 'self' and
in runLoopMode. =/
but when I debug, it skips over the whole thing
On Jul 23, 2009, at 1:39 PM, Eli Bach wrote:
On Jul 23, 2009, at 11:24 AM, DerNalia wrote:
I have all this code I got from the Apple Developer site, It all
sets up correctly. Assuming I can trust my NSLogs, I should be
connected to my telnet server.
So, lets I say I want to send the command "!COMMAND ARG"
Since this:
- (void)stream:(NSStream *)stream handleEvent:
(NSStreamEvent)eventCode
sounds like it should do what I want, and NSStreamEvent is an
NSUInteger, do I just break up the command char by char, and send
it to this method?
Um, nope.
- (void)stream:(NSStream *)theStream handleEvent:
(NSStreamEvent)streamEvent
is a method you implement in one of your classes, of which you
create an instance and then set that instance to be the delegate of
either the NSInputStream or NSOutputStream (or both). It is how the
stream object tells you what is happening to the stream (such as the
stream has opened, closed, received an error, etc...).
Since you need to send some data to the remote server, I believe you
will need to use the NSOutputStream method:
-(NSInteger)write:(const uint8_t *)buffer maxLength:(NSUInteger)length
This is from <http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Classes/NSOutputStream_Class/Reference/Reference.html#//apple_ref/doc/uid/20001983-BAJCCBCH
>
You may want to click on that link, then download the 'CocoaEcho'
sample code that is available there.
Eli
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Macnetworkprog mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Macnetworkprog mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden