Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
20
Task/Sockets/Objective-C/sockets.m
Normal file
20
Task/Sockets/Objective-C/sockets.m
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
// declare the class to conform to NSStreamDelegate protocol
|
||||
|
||||
// in some method
|
||||
NSOutputStream *oStream;
|
||||
[NSStream getStreamsToHost:[NSHost hostWithName:@"localhost"] port:256 inputStream:NULL outputStream:&oStream];
|
||||
[oStream setDelegate:self];
|
||||
[oStream scheduleInRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode];
|
||||
[oStream open];
|
||||
|
||||
|
||||
// later, in the same class:
|
||||
- (void)stream:(NSStream *)aStream handleEvent:(NSStreamEvent)streamEvent {
|
||||
NSOutputStream *oStream = (NSOutputStream *)aStream;
|
||||
if (streamEvent == NSStreamEventHasBytesAvailable) {
|
||||
NSString *str = @"hello socket world";
|
||||
const char *rawstring = [str UTF8String];
|
||||
[oStream write:rawstring maxLength:strlen(rawstring)];
|
||||
[oStream close];
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue