// Initialize a client
//
// Initialization can be done with C function pointers, Obj-C delegates, or
// by passing in Obj-C blocks.
self.client = [[HydrogenClient alloc] initWithHydrogenDelegate:self];
// Connect to a hydrogen server
NSString *hostAddress = @"127.0.0.1";
uint16_t port = 1337;
[self.client connectToHostWithAddress:hostAddress andPort:port];
// Send a thing to server
const char *ping = "ping";
NSData *buffer = [[NSData alloc] initWithBytes:ping length:4];
[self.client write:buffer];
// Disconnect
[self.client disconnect];
// Hydrogen Protocol
// Called when connection to host has been established
- (void)onConnected
{
NSLog(@"onConnected");
}
// Called when connection to host has been lost
- (void)onDisconnected
{
NSLog(@"onDisconnected");
}
// Called when data is received from host
- (void)onDataReceived:(const uint8_t *)buffer withLen:(const size_t)len
{
NSLog(@"onDataReceived");
// Consumer is responsible for freeing buffer
}
// Called when an error has been encountered
- (void)onError:(HydrogenResult)error
{
NSLog(@"onError");
}
hydrogen-objc 通过 CocoaPods 提供。要安装它,只需将以下行添加到您的 Podfile 中
pod "hydrogen-objc"
Nathan Sizemore, [email protected]
hydrogen-objc 在 MPL-2.0 许可证下提供。有关更多信息,请参阅 LICENSE 文件。