• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Help with NSStream getStreamsToHost
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Help with NSStream getStreamsToHost


  • Subject: Help with NSStream getStreamsToHost
  • From: Adam <email@hidden>
  • Date: Sun, 18 Apr 2004 18:00:24 -0400

<newbieDisclaimer>

I am trying to use the apple document "Setting Up Socket Streams" (http://developer.apple.com/documentation/Cocoa/Conceptual/Streams/ Articles/NetworkStreams.html) to connect to a telnet server. I wrote the following code and get no output. I am trying to print what was returned in the buffer after the connection. I get no output except for my first "hi"


Thanks.
Adam


int main(int argc, const char *argv[])
{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];

NSLog(@"hi:");
NSHost *aHost = [NSHost hostWithName:@"fibs.com"];
NSInputStream *iStream = [[NSTask alloc] init];
NSOutputStream *oStream = [[NSTask alloc] init];
[NSStream getStreamsToHost:aHost port:4321 inputStream:&iStream outputStream:&oStream];
[iStream retain];
[oStream retain];
[iStream setDelegate:iStream];
[oStream setDelegate:oStream];
[iStream scheduleInRunLoop:[NSRunLoop currentRunLoop]
forMode:NSDefaultRunLoopMode];
[oStream scheduleInRunLoop:[NSRunLoop currentRunLoop]
forMode:NSDefaultRunLoopMode];
[iStream open];
[oStream open];
NSMutableData *_data = [[NSMutableData alloc] init];
int bytesRead;
if(!_data) {
_data = [[NSMutableData data] retain];
}
uint8_t buf[1024];
unsigned int len = 0;
unsigned char secondBuffer[20];
len = [(NSInputStream *)iStream read:buf maxLength:1024];
if(len) {
[_data appendBytes:(const void *)buf length:len];
bytesRead = bytesRead +len;
} else {
NSLog(@"no buffer!");
}
[_data getBytes:secondBuffer];
NSLog(@"hi2:");
NSLog(@"hi2:", (char *)secondBuffer);
[pool release];
return NSApplicationMain(argc, argv);
}
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.


  • Prev by Date: Re: NSObjectController and NSDefaultsController Binding?
  • Next by Date: Re: NSObjectController and NSDefaultsController Binding?
  • Previous by thread: Re: Rapid use of NSTextField
  • Next by thread: [ANN] Graphviz sources now available!
  • Index(es):
    • Date
    • Thread