Skip to content
High-throughput, synchronous Objective-C wrapper around BSD sockets for iOS and macOS.
Objective-C Ruby
Branch: master
Clone or download
dreese Merge pull request #32 from dreese/create-changelog
Split release notes into new CHANGELOG file
Latest commit f7f43e6 Apr 10, 2018
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
FastSocket.xcodeproj Split release notes into new CHANGELOG file Apr 10, 2018
.gitignore updated to the github recommended gitignore file for objective-c and … Oct 8, 2013
CHANGELOG.md Split release notes into new CHANGELOG file Apr 10, 2018
CONTRIBUTING.md Add initial version of contribution guidelines. Oct 18, 2017
FastServerSocket.h Added __attribute__((nonnull)) for methods that expect non-nil values. May 29, 2014
FastServerSocket.m changing types again so that public api is less confusing. time_t and… Jul 27, 2013
FastSocket.h Annotate code so that the auto-generated Swift equivalent is nicer. Oct 19, 2017
FastSocket.m Fix a bug where the socket state could become inconsistent Nov 2, 2017
FastSocket.podspec Updated README and podspec for v1.6 Nov 2, 2017
FastSocketTest.m Update timeout tests with easier to remember host. Nov 2, 2017
LICENSE
README.md Merge pull request #32 from dreese/create-changelog Apr 10, 2018
UnitTests-Info.plist Upgrade to Xcode 9 settings Nov 2, 2017

README.md

FastSocket

Description

A high-throughput, synchronous Objective-C wrapper around BSD sockets for iOS and macOS. Send and receive raw bytes over a socket as fast as possible. Includes methods for transferring files while optionally computing a checksum for verification. Swift compatible.

Use this class if fast network communication is what you need. If you want to do something else while your network operations finish, then an asynchronous API might be better.

For more information, please visit the project homepage. FastSocket is also available as a CocoaPod.

Download

Download the latest release of FastSocket or try the nightly version.

Examples

Create and connect a client socket.

FastSocket *client = [[FastSocket alloc] initWithHost:@"localhost" andPort:@"34567"];
[client connect];

Send a file.

long sent = [client sendFile:@"/tmp/filetosend.txt"];

Receive a file of a given length.

long received = [client receiveFile:@"/tmp/newlyreceivedfile.txt" length:1024];

Send a string.

NSData *data = [@"test" dataUsingEncoding:NSUTF8StringEncoding];
long count = [client sendBytes:[data bytes] count:[data length]];

Receive a string.

char bytes[expectedLength];
[client receiveBytes:bytes count:expectedLength];
NSString *received = [[NSString alloc] initWithBytes:bytes length:expectedLength encoding:NSUTF8StringEncoding];

Send raw bytes.

char data[] = {42};
long sent = [client sendBytes:data count:1];

Receive available raw bytes up to the given limit.

char data[42];
long received = [client receiveBytes:data limit:42];

Receive the exact number of raw bytes given.

char data[1000];
long received = [client receiveBytes:data count:1000];

Close the connection.

[client close];

Please check out the unit tests for more examples of how to use these classes.

Creator

Daniel Reese @dreese

License

FastSocket is available under the MIT license.

You can’t perform that action at this time.