Skip to content

Instantly share code, notes, and snippets.

@beelsebob
Created July 12, 2011 12:41
Show Gist options
  • Save beelsebob/1077898 to your computer and use it in GitHub Desktop.
Save beelsebob/1077898 to your computer and use it in GitHub Desktop.
- (void)connect
{
CFReadStreamRef readStream;
CFWriteStreamRef writeStream;
CFStreamCreatePairWithSocketToHost(NULL,
SERVER,
PORT,
&readStream,
&writeStream);
[self setInputStream:(NSInputStream *)readStream];
[self setOutputStream:(NSOutputStream *)writeStream];
CFRelease(readStream);
CFRelease(writeStream);
hasConnected = NO;
[[self inputStream] setDelegate:self];
[[self outputStream] setDelegate:self];
NSRunLoop *runLoop = [NSRunLoop currentRunLoop];
[[self inputStream] scheduleInRunLoop:runLoop forMode:NSDefaultRunLoopMode];
[[self outputStream] scheduleInRunLoop:runLoop forMode:NSDefaultRunLoopMode];
[[self inputStream] open];
[[self outputStream] open];
}
- (void)stream:(NSStream *)aStream handleEvent:(NSStreamEvent)eventCode
{
switch (eventCode)
...
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment