NSFileHandleExt

NSFileHandleExt is an extension for the Objective-C/Cocoa-class NSFileHandle, which is used for handling files and sockets
Download

NSFileHandleExt Ranking & Summary

Advertisement

  • Rating:
  • License:
  • BSD License
  • Price:
  • FREE
  • Publisher Name:
  • Michael Stapelberg
  • Publisher web site:
  • http://michael.stapelberg.de/mxallowd.en

NSFileHandleExt Tags


NSFileHandleExt Description

NSFileHandleExt is an extension for the Objective-C/Cocoa-class NSFileHandle, which is used for handling files and sockets NSFileHandleExt is an extension for the Objective-C/Cocoa-class NSFileHandle, which is used for handling files and sockets. NSFileHandleExt extension adds the methods +(id)fileHandleWithConnectionToHost:(NSString*)host toPort:(int)port; and -(NSString*)readLine; aswell as -(void)writeLine:(NSString*)line;, which are wrappers around the BSD-sockets. So, this allows you to use a socket efficiently.Methods:+(id)fileHandleWithConnectionToHost:(NSString*)host toPort:(int)portThis method returns a new NSFileHandle after establishing a connection to the given host on the given port. If the connection could not be established, an exception will be thrown.-(NSString*)readLineThis method reads a line from the socket and returns it. The end of a line is recognized by the trailing "n".-(void)writeLine:(NSString*)lineWrites the given line with a trailing "rn" to the socket.Example:This example connects to port 80 of the local machine and sends an HTTP-request. The result of the server is print into the log window, afterwards the connection will be closed.NS_DURING { NSFileHandle *connection = ; ; ; ; NSString *reply = ; while ( > 0) { NSLog(@"Got line: %@", reply); reply = ; } ;} NS_HANDLER { NSLog(@"Error talking to server: %@", );} NS_ENDHANDLERBefore using, you have to import the extension using #import "NSFileHandleExt.h" and add both files (NSFileHandleExt.h and NSFileHandleExt.m) to the project.


NSFileHandleExt Related Software