CoSocket
A fast, synchronous Objective-C wrapper around BSD sockets for iOS and OS X.
Install / Use
/learn @codinn/CoSocketREADME
CoSocket
This project is originally forked from FastSocket, and later influenced by GCDAsyncSocket.
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.
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.
Download
Examples
Create and connect a client socket.
CoSocket *client = [[CoSocket alloc] init];
BOOL result = [client connectToHost:@"localhost" onPort:34567 withTimeout:10.0 error:nil];
Send a string.
NSData *data = [@"test" dataUsingEncoding:NSUTF8StringEncoding];
result = [client writeData:data error:nil];
Receive a string.
NSData *data = [client readDataToLength:expectedLength error:nil];
NSString *received = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
Send raw bytes.
char rawData[] = {42};
NSData *data = [NSData dataWithBytes:rawData length:42];
long sent = [client writeData:data error:nil];
Reads bytes until (and including) a separator encountered.
NSData *data = [client readDataToData:[CoSocket CRLFData] error:nil];
Close the connection.
[client disconnect];
Please check out the unit tests for more examples of how to use these classes.
License
CoSocket is available under the MIT license.
Related Skills
node-connect
343.1kDiagnose OpenClaw node connection and pairing failures for Android, iOS, and macOS companion apps
frontend-design
90.0kCreate distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, or applications. Generates creative, polished code that avoids generic AI aesthetics.
openai-whisper-api
343.1kTranscribe audio via OpenAI Audio Transcriptions API (Whisper).
qqbot-media
343.1kQQBot 富媒体收发能力。使用 <qqmedia> 标签,系统根据文件扩展名自动识别类型(图片/语音/视频/文件)。
