# socket_object **Repository Path**: adiljan.git/socket_object ## Basic Information - **Project Name**: socket_object - **Description**: 这是socket 服务的objective-c 项目 cocoapods 导入pod 'Socket.IO-Client-Swift' - **Primary Language**: Unknown - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2018-03-15 - **Last Updated**: 2020-12-19 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README [![Build Status](https://travis-ci.org/socketio/socket.io-client-swift.svg?branch=master)](https://travis-ci.org/socketio/socket.io-client-swift) # socket_object # 本地服务器配置 终端进入socket目录, 运行 node index.js 命令启动服务器 ## Example ```swift import SocketIO let manager = SocketManager(socketURL: URL(string: "http://localhost:8080")!, config: [.log(true), .compress]) let socket = manager.defaultSocket socket.on(clientEvent: .connect) {data, ack in print("socket connected") } socket.on("currentAmount") {data, ack in guard let cur = data[0] as? Double else { return } socket.emitWithAck("canUpdate", cur).timingOut(after: 0) {data in socket.emit("update", ["amount": cur + 2.50]) } ack.with("Got your currentAmount", "dude") } socket.connect() ``` ## Objective-C Example ```objective-c @import SocketIO; NSURL* url = [[NSURL alloc] initWithString:@"http://localhost:8080"]; SocketManager* manager = [[SocketManager alloc] initWithSocketURL:url config:@{@"log": @YES, @"compress": @YES}]; SocketIOClient* socket = manager.defaultSocket; [socket on:@"connect" callback:^(NSArray* data, SocketAckEmitter* ack) { NSLog(@"socket connected"); }]; [socket on:@"currentAmount" callback:^(NSArray* data, SocketAckEmitter* ack) { double cur = [[data objectAtIndex:0] floatValue]; [[socket emitWithAck:@"canUpdate" with:@[@(cur)]] timingOutAfter:0 callback:^(NSArray* data) { [socket emit:@"update" with:@[@{@"amount": @(cur + 2.50)}]]; }]; [ack with:@[@"Got your currentAmount, ", @"dude"]]; }]; [socket connect]; ``` ### CocoaPods 1.0.0 or later Create `Podfile` and add `pod 'Socket.IO-Client-Swift'`: ```ruby use_frameworks! target 'YourApp' do pod 'Socket.IO-Client-Swift', '~> 13.1.0' end ``` Install pods: ``` $ pod install ``` Import the module: Swift: ```swift import SocketIO ``` Objective-C: ```Objective-C @import SocketIO; ``` # [Docs](https://nuclearace.github.io/Socket.IO-Client-Swift/index.html) - [Client](https://nuclearace.github.io/Socket.IO-Client-Swift/Classes/SocketIOClient.html) - [Manager](https://nuclearace.github.io/Socket.IO-Client-Swift/Classes/SocketManager.html) - [Engine](https://nuclearace.github.io/Socket.IO-Client-Swift/Classes/SocketEngine.html) - [Options](https://nuclearace.github.io/Socket.IO-Client-Swift/Enums/SocketIOClientOption.html) ## Detailed Example A more detailed example can be found [here](https://github.com/nuclearace/socket.io-client-swift-example) An example using the Swift Package Manager can be found [here](https://github.com/nuclearace/socket.io-client-swift-spm-example) ## License MIT