Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/youngmonkeys/ezyfox-server-swift-client
ezyfox-server-swift-client
https://github.com/youngmonkeys/ezyfox-server-swift-client
ios swift swift-client swift-socket tcp-socket
Last synced: about 1 month ago
JSON representation
ezyfox-server-swift-client
- Host: GitHub
- URL: https://github.com/youngmonkeys/ezyfox-server-swift-client
- Owner: youngmonkeys
- Created: 2018-10-30T09:50:20.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2023-10-15T16:03:02.000Z (about 1 year ago)
- Last Synced: 2024-04-24T08:50:53.624Z (8 months ago)
- Topics: ios, swift, swift-client, swift-socket, tcp-socket
- Language: Swift
- Size: 51.8 KB
- Stars: 1
- Watchers: 3
- Forks: 4
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# ezyfox-server-swift-client
swift client for ezyfox server# Synopsis
swift client for ezyfox server
# Documentation
[https://youngmonkeys.org/ezyfox-swift-client-sdk/](https://youngmonkeys.org/ezyfox-swift-client-sdk/)
# Using by
- [freechat](https://github.com/youngmonkeys/freechat)
# Code Example
**1. Create a TCP Client**
```swift
let config = NSMutableDictionary()
config["clientName"] = ZONE_APP_NAME
let clients = EzyClients.getInstance()!
client = clients.newClient(config: config)
```**2. Setup client**
```swift
let setup = client.setup!
.addEventHandler(eventType: EzyEventType.CONNECTION_SUCCESS, handler: EzyConnectionSuccessHandler())
.addEventHandler(eventType: EzyEventType.CONNECTION_FAILURE, handler: EzyConnectionFailureHandler())
.addEventHandler(eventType: EzyEventType.DISCONNECTION, handler: ExDisconnectionHandler())
.addDataHandler(cmd: EzyCommand.LOGIN, handler: ExLoginSuccessHandler())
.addDataHandler(cmd: EzyCommand.APP_ACCESS, handler: ExAppAccessHandler())
.addDataHandler(cmd: EzyCommand.HANDSHAKE, handler: ExHandshakeHandler())
```**3. Setup app**
```swift
= setup.setupApp(appName: ZONE_APP_NAME)
.addDataHandler(cmd: Commands.GET_CONTACTS, handler: GetContactsResponseHandler())
.addDataHandler(cmd: Commands.SEARCH_EXISTED_CONTACTS, handler: SearchExistedContactsResponseHandler())
.addDataHandler(cmd: Commands.SUGGEST_CONTACTS, handler: SuggestContactsResponseHandler())
```**4. Connect to server**
```swift
client.connect(host: host, port: 3005)
```**5. Run event loop**
```swift
clients.processEvents()
```**6. Custom event handler**
```swift
class ExDisconnectionHandler: EzyDisconnectionHandler {
override func postHandle(event: NSDictionary) {
// do something here
}
}
```**8. Logger usage**
You should set main thread's name first:
```swift
Thread.current.name = "main";
```Logger usage:
```swift
EzyLogger.info(msg: "access app: \(app.name) successfully")
```