Skip to content

Commit

Permalink
Example is added.
Browse files Browse the repository at this point in the history
  • Loading branch information
WrathChaos committed Jul 10, 2017
1 parent 321d2e5 commit fdd8b87
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 7 deletions.
57 changes: 51 additions & 6 deletions Example/StompClientLib/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,62 @@
//

import UIKit
import StompClientLib

class ViewController: UIViewController {
class ViewController: UIViewController, StompClientLibDelegate {

var socketClient = StompClientLib()

override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.

// Connection with socket
registerSocket()
}

override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.

func registerSocket(){
let baseURL = "http://your-url-is-here/"
// Cut the first 7 character which are "http://" Not necessary!!!
let wsURL = baseURL.substring(from:baseURL.index(baseURL.startIndex, offsetBy: 7))
let completedWSURL = "ws://\(wsURL)gateway/websocket"
print("Completed WS URL : \(completedWSURL)")
let url = NSURL(string: completedWSURL)!

socketClient.openSocketWithURLRequest(request: NSURLRequest(url: url as URL) , delegate: self as StompClientLibDelegate)
}

func stompClientDidConnect(client: StompClientLib!) {
let topic = "/topic/your topic is here/"
print("Socket is Connected : \(topic)")
socketClient.subscribe(destination: topic)
}

func stompClientDidDisconnect(client: StompClientLib!) {
print("Socket is Disconnected")
}

func stompClientWillDisconnect(client: StompClientLib!, withError error: NSError) {

}


func stompClient(client: StompClientLib!, didReceiveMessageWithJSONBody jsonBody: AnyObject?, withHeader header: [String : String]?, withDestination destination: String) {
print("DESTIONATION : \(destination)")
print("JSON BODY : \(String(describing: jsonBody))")
}


func serverDidSendReceipt(client: StompClientLib!, withReceiptId receiptId: String) {
print("Receipt : \(receiptId)")
}


func serverDidSendError(client: StompClientLib!, withErrorMessage description: String, detailedErrorMessage message: String?) {
print("Error : \(String(describing: message))")
}

func serverDidSendPing() {
print("Server Ping")
}

}
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# StompClientLib

[![CI Status](http://img.shields.io/travis/wrathchaos/StompClientLib.svg?style=flat)](https://travis-ci.org/wrathchaos/StompClientLib)
[](https://img.shields.io/badge/Swift-3.0-blue.svg?style=flat)
![](https://img.shields.io/badge/Swift-3.0-blue.svg?style=flat)
[![Version](https://img.shields.io/cocoapods/v/StompClientLib.svg?style=flat)](http://cocoapods.org/pods/StompClientLib)
[![License](https://img.shields.io/cocoapods/l/StompClientLib.svg?style=flat)](http://cocoapods.org/pods/StompClientLib)
[![Platform](https://img.shields.io/cocoapods/p/StompClientLib.svg?style=flat)](http://cocoapods.org/pods/StompClientLib)
Expand Down

0 comments on commit fdd8b87

Please sign in to comment.