Socket.io-client-swift: the manager and engine are being released

Created on 7 Feb 2018  ·  1Comment  ·  Source: socketio/socket.io-client-swift

On my node backend server, it says that something connected when I run this, but then I get the error below and if I try emitting events, it says the other error below

swift code:

import UIKit
import SocketIO

class ViewController: UIViewController {

@IBOutlet weak var messagesBody: UITextView!
@IBOutlet weak var newMessageInput: UITextField!
@IBOutlet weak var newMessageSubmit: UIButton!

var socket:SocketIOClient!

override func viewDidLoad() {
    super.viewDidLoad()

    let manager = SocketManager(socketURL: URL(string: "http://localhost:3000/chat.html?name=developer&room=test")!, config: [.log(true), .compress])
    self.socket = manager.socket(forNamespace: "/")

    establishSocketConnection()

    newMessageSubmit.addTarget(self, action: #selector(sendNewMessage), for: .touchUpInside)
}

override func didReceiveMemoryWarning() {
    super.didReceiveMemoryWarning()
}

func establishSocketConnection() {
    self.socket.connect()
    self.socket.on("connect") { ( dataArray, ack) -> Void in
        print("connected to external server")
    }
}

func cloesSocketConnection() {
    self.socket.disconnect()
}

@objc func sendNewMessage() {
    let newMessageContent = newMessageInput.text!
    print("Sending message..." + newMessageContent)
    self.socket.emit("createMessage", newMessageContent)
}
}

main error:

2018-02-07 17:53:33.809954-0500 chat-app[78163:6477441] [MC] Lazy loading NSBundle MobileCoreServices.framework
2018-02-07 17:53:33.811229-0500 chat-app[78163:6477441] [MC] Loaded MobileCoreServices.framework
2018-02-07 17:53:33.915820-0500 chat-app[78163:6477441] LOG SocketIOClient{/swift}: Handling event: statusChange with data: [connecting]
2018-02-07 17:53:33.916535-0500 chat-app[78163:6477441] LOG SocketIOClient{/swift}: Joining namespace /swift
2018-02-07 17:53:33.918305-0500 chat-app[78163:6477441] LOG SocketManager: Tried connecting socket when engine isn't open. Connecting
2018-02-07 17:53:33.918627-0500 chat-app[78163:6477441] LOG SocketManager: Adding engine
2018-02-07 17:53:33.921886-0500 chat-app[78163:6477498] LOG SocketEngine: Starting engine. Server: http://localhost:3000/chat.html?name=developer&room=test
2018-02-07 17:53:33.922020-0500 chat-app[78163:6477498] LOG SocketEngine: Handshaking
2018-02-07 17:53:33.922060-0500 chat-app[78163:6477441] LOG SocketIOClient{/swift}: Adding handler for event: connect
2018-02-07 17:53:33.922966-0500 chat-app[78163:6477441] LOG SocketManager: Manager is being released
2018-02-07 17:53:33.924349-0500 chat-app[78163:6477498] LOG SocketEnginePolling: Doing polling GET http://localhost:3000/socket.io/?transport=polling&b64=1
2018-02-07 17:53:34.014299-0500 chat-app[78163:6477498] LOG SocketEnginePolling: Got polling response
2018-02-07 17:53:34.016531-0500 chat-app[78163:6477498] LOG SocketEnginePolling: Got poll message: 97:0{"sid":"DRRfs3CyuXRDeYVIAAAA","upgrades":["websocket"],"pingInterval":25000,"pingTimeout":60000}
2018-02-07 17:53:34.022590-0500 chat-app[78163:6477498] LOG SocketEngine: Got message: 0{"sid":"DRRfs3CyuXRDeYVIAAAA","upgrades":["websocket"],"pingInterval":25000,"pingTimeout":60000}
2018-02-07 17:53:34.045912-0500 chat-app[78163:6477498] LOG SocketEngine: Writing poll: has data: false
2018-02-07 17:53:34.046635-0500 chat-app[78163:6477498] LOG SocketEnginePolling: Sending poll: as type: 2
2018-02-07 17:53:34.048335-0500 chat-app[78163:6477498] LOG SocketEnginePolling: Created POST string: 1:2
2018-02-07 17:53:34.049790-0500 chat-app[78163:6477498] LOG SocketEnginePolling: POSTing
2018-02-07 17:53:34.050572-0500 chat-app[78163:6477498] LOG SocketEngine: Engine is being released

emitting events error:

2018-02-07 17:53:37.918418-0500 chat-app[78163:6477441] LOG SocketIOClient{/swift}: Handling event: error with data: ["Tried emitting createMessage when not connected"]

Most helpful comment

need to add this:
var socketManager:SocketManager!

>All comments

need to add this:
var socketManager:SocketManager!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

gaetanm picture gaetanm  ·  4Comments

huangxiaolin0425 picture huangxiaolin0425  ·  6Comments

njawahire picture njawahire  ·  4Comments

astrike30 picture astrike30  ·  6Comments

elitelokesh picture elitelokesh  ·  6Comments