Code Monkey home page Code Monkey logo

fastsocket's Introduction

FastSocket

Description

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

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.

Release Notes

2017 Nov 01 — v1.6

• Fixed a long-standing bug where the internal socket descriptor could become closed but not zeroed out.

2017 Oct 28 — v1.5

• Annotated code to improve auto-generated Swift interface.
• Fixed several documentation issues.
• Added document for contributions.

2017 Oct 06 — v1.4

• Changed -[FaskSocket timeout] and -[FaskSocket setTimeout:] methods so that the timeout value is a float, in order to handle sub-second values.
• Fixed a compatibility issue with Xcode 9.
• Added several unit tests.

2015 Jan 27 — v1.3

• Changed -[FaskSocket sendBytes:count:] method to return the actual number of bytes received instead of a BOOL. Now it matches the Readme.
• Fixed a compiler warning caused by returning NO instead of nil from one of the init methods.
• Added several unit tests.

2014 Feb 03 — v1.2

• Added -[FastSocket connect:] method for specifying a connection timeout, which is separate from the read/write timeout.
• Added CocoaPod support with new podspec file.

2013 Oct 03 — v1.1

• Converted to ARC.
• Added -[FastSocket isConnected] method.
• Added -[FastSocket receiveBytes:count:] method for receiving an exact number of bytes. This differs from -[FastSocket receiveBytes:limit:] in that the new method waits for the given number of bytes is received, or a timeout, before returning.
• Added header documentation for use in Xcode 5.

2012 Jun 24 — v1.0

• Initial release.

Creator

Daniel Reese @dreese

License

FastSocket is available under the MIT license.

fastsocket's People

Contributors

babysnakes42 avatar

Stargazers

 avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.