Closed mithun-grmtech closed 5 years ago
@mithun-grmtech The issue lies in
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
// Call my socket
let mySocket = MySocket();
mySocket.connected();
}
Here you're declaring mySocket
as a local variable. The problem with this is mySocket
will get released by ARC as soon as the method returns. Which you can see in the logs:
2019-04-23 15:46:48.556153+0530 Clinic Check In[7155:375299] LOG SocketManager: Manager is being released
...
2019-04-23 15:46:48.556339+0530 Clinic Check In[7155:375299] LOG SocketIOClient{/swift}: Client is being released
...
2019-04-23 15:46:49.874290+0530 Clinic Check In[7155:375701] LOG SocketEngine: Engine is being released
You need to make sure the thing that holds the SocketManager
is held strongly, and not released by ARC for as long as you want to maintain an active connection.
@nuclearace thank you for response
Now it's working fine.
My server is using socket.io of nodJS. I can not connect server through websocket. The code and log are as follows:
My project version: 4.0 My pod version : 1.5.3
Step 1: I created a new file MySocket.swift
Step 2: This is controller file HomeViewController.swift
Logs:
2019-04-23 15:46:48.554479+0530 Clinic Check In[7155:375299] LOG SocketIOClient{/swift}: Adding handler for event: connect 2019-04-23 15:46:48.554785+0530 Clinic Check In[7155:375299] LOG SocketIOClient{/swift}: Adding handler for event: error 2019-04-23 15:46:48.554968+0530 Clinic Check In[7155:375299] LOG SocketIOClient{/swift}: Adding handler for event: itsMyPersonalChanel 2019-04-23 15:46:48.555223+0530 Clinic Check In[7155:375299] LOG SocketIOClient{/swift}: Handling event: statusChange with data: [connecting] 2019-04-23 15:46:48.555391+0530 Clinic Check In[7155:375299] LOG SocketManager: Tried connecting socket when engine isn't open. Connecting 2019-04-23 15:46:48.555537+0530 Clinic Check In[7155:375299] LOG SocketManager: Adding engine 2019-04-23 15:46:48.556153+0530 Clinic Check In[7155:375299] LOG SocketManager: Manager is being released 2019-04-23 15:46:48.556213+0530 Clinic Check In[7155:375702] LOG SocketEngine: Starting engine. Server: https://www.abc.com/ 2019-04-23 15:46:48.556339+0530 Clinic Check In[7155:375299] LOG SocketIOClient{/swift}: Client is being released 2019-04-23 15:46:48.556341+0530 Clinic Check In[7155:375702] LOG SocketEngine: Handshaking 2019-04-23 15:46:48.558049+0530 Clinic Check In[7155:375702] LOG SocketEnginePolling: Doing polling GET https://www.abc.com/socket.io/?transport=polling&b64=1 2019-04-23 15:46:49.868672+0530 Clinic Check In[7155:375701] LOG SocketEnginePolling: Got polling response 2019-04-23 15:46:49.868898+0530 Clinic Check In[7155:375701] LOG SocketEnginePolling: Got poll message: 97:0{"sid":"3CH1041hymjxjSRmAAvm","upgrades":["websocket"],"pingInterval":25000,"pingTimeout":60000} 2019-04-23 15:46:49.869308+0530 Clinic Check In[7155:375701] LOG SocketEngine: Got message: 0{"sid":"3CH1041hymjxjSRmAAvm","upgrades":["websocket"],"pingInterval":25000,"pingTimeout":60000} 2019-04-23 15:46:49.872672+0530 Clinic Check In[7155:375701] LOG SocketEngine: Writing poll: has data: false 2019-04-23 15:46:49.872949+0530 Clinic Check In[7155:375701] LOG SocketEnginePolling: Sending poll: as type: 2 2019-04-23 15:46:49.873509+0530 Clinic Check In[7155:375701] LOG SocketEnginePolling: Created POST string: 1:2 2019-04-23 15:46:49.873941+0530 Clinic Check In[7155:375701] LOG SocketEnginePolling: POSTing 2019-04-23 15:46:49.874290+0530 Clinic Check In[7155:375701] LOG SocketEngine: Engine is being released