Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 34 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,46 +26,64 @@ Examples

Create and connect a client socket.

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

Send a file.

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

Receive a file of a given length.

long received = [client receiveFile:@"/tmp/newlyreceivedfile.txt" length:1024];
```objc
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]];
```objc
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];
```objc
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];
```objc
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];
```objc
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];
```objc
char data[1000];
long received = [client receiveBytes:data count:1000];
```

Close the connection.

[client close];
```objc
[client close];
```

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

Expand Down