Hi i'm getting this error in the XCode console after a few seconds it did connect to the server:
"JSON string conversion error: The data couldn’t be read because it isn’t in the correct format."
ERROR JSONStringConversionError("9")
After that the client disconnects from server. Don't know if this is a bug or i did a mistake
I'm running clusterws 3.0.6 on macOS 10.13.4, node.js v8.11.2 and XCode 9.3.1 with iOS 11.3
import UIKit
import ClusterWS_Client_Swift
class ViewController: UIViewController, CWSDelegate {
let webSocket = ClusterWS(url: "ws://localhost:3003")
@IBAction func connectButtonTapped(_ sender: UIButton) {
webSocket.connect()
}
@IBAction func disconnectButtonTapped(_ sender: UIButton) {
webSocket.disconnect()
}
override func viewDidLoad() {
super.viewDidLoad()
webSocket.delegate = self
}
func onConnect() {
print("CONNECTED")
}
func onDisconnect(code: Int?, reason: String?) {
print("DISCONNECTED", code, reason)
}
func onError(error: Error) {
print("ERROR", error)
}
}
// Import clusterws
const ClusterWS = require('clusterws')
// Import your library/framework
const express = require('express')
// Configure ClusterWS
const clusterws = new ClusterWS({
worker: Worker, // Worker function must be provided
port: 3003
})
// Worker function with all your server logic
function Worker() {
// Get websocket server
const wss = this.wss
// Get http/https server
const server = this.server
// Use your library/framework as you usually do
const app = express()
app.get('/home', (req, res, next) => {})
// Connect ClusterWS and your library/framework
server.on('request', app)
// Listen on WebSocket connection
wss.on('connection', (socket) => {
console.log('Connected to ws')
})
}