From 01c07187affe7f2cbe2445751beaed7770be3157 Mon Sep 17 00:00:00 2001 From: Happy Date: Mon, 13 Jul 2020 21:07:45 -0700 Subject: [PATCH] Add syntax highlighting to readme --- README.md | 50 ++++++++++++++++++++++++++++++++++---------------- 1 file changed, 34 insertions(+), 16 deletions(-) diff --git a/README.md b/README.md index fb3d27d..578eb99 100644 --- a/README.md +++ b/README.md @@ -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.