Socket.io-client-swift: Trying to send messages to Flask SocketIO server

Created on 12 Mar 2018  路  6Comments  路  Source: socketio/socket.io-client-swift

I am trying to connect and send messages to a FlaskIO socket. I have managed to establish the connection between my client (iOS) and the python server but I cannot send messages.

I am trying to send a string to the following function:

@socketio.on('message')
def handle_message(message):
    print('received message: ' + message)

I am using the Swift method on my SocketIOClient object: socket.emit("message", "testmessage") (which again has successfully connected to the socket itself).

Please can you tell me where I am going wrong here and I am happy to provide more information if you require it.

Most helpful comment

2018-04-03 23:55:22.421797+0400 SwiftIPhone[36889:1387350] LOG SocketManager: Manager is being released. The manager needs to be a propery or global. It's getting released by ARC.

All 6 comments

@astrike30 are you able to receive messages? Can you post server/client logs?

I have same problem too. There is production flask server, tested with browser.
When connecting through ios:

let address = "ws://localhost:5000/"

let manager = SocketManager(socketURL: URL(string: address)!, config: [.log(true), .compress, .forceWebsockets(false)])

let socket = manager.socket(forNamespace: "/anon")
socket.on(clientEvent: .connect) {data, ack in
     print("socket connected")//never print
}

socket.connect()

connect just to '/' (not to '/anon') namespace will be triggered, but ios doesn't receive connect event .

When i set .forceWebosckets(true) it doesn't works at all:(

Can you post some logs?

2018-04-03 23:55:22.419166+0400 SwiftIPhone[36889:1387350] LOG SocketIOClient{/anon}: Adding handler for event: connect
2018-04-03 23:55:22.419599+0400 SwiftIPhone[36889:1387350] LOG SocketIOClient{/anon}: Handling event: statusChange with data: [connecting]
2018-04-03 23:55:22.419953+0400 SwiftIPhone[36889:1387350] LOG SocketIOClient{/anon}: Joining namespace /anon
2018-04-03 23:55:22.420179+0400 SwiftIPhone[36889:1387350] LOG SocketManager: Tried connecting socket when engine isn't open. Connecting
2018-04-03 23:55:22.421295+0400 SwiftIPhone[36889:1387350] LOG SocketManager: Adding engine
2018-04-03 23:55:22.421797+0400 SwiftIPhone[36889:1387350] LOG SocketManager: Manager is being released
2018-04-03 23:55:22.421888+0400 SwiftIPhone[36889:1387468] LOG SocketEngine: Starting engine. Server: ws://localhost:5000/
2018-04-03 23:55:22.422201+0400 SwiftIPhone[36889:1387350] LOG SocketIOClient{/anon}: Client is being released
2018-04-03 23:55:22.422369+0400 SwiftIPhone[36889:1387468] LOG SocketEngine: Handshaking
2018-04-03 23:55:22.425341+0400 SwiftIPhone[36889:1387468] LOG SocketEngine: Engine is being released

When .forceWebsockets(true)

2018-04-03 23:57:53.459484+0400 SwiftIPhone[36986:1390892] LOG SocketIOClient{/anon}: Adding handler for event: connect
2018-04-03 23:57:53.459963+0400 SwiftIPhone[36986:1390892] LOG SocketIOClient{/anon}: Handling event: statusChange with data: [connecting]
2018-04-03 23:57:53.460250+0400 SwiftIPhone[36986:1390892] LOG SocketIOClient{/anon}: Joining namespace /anon
2018-04-03 23:57:53.460652+0400 SwiftIPhone[36986:1390892] LOG SocketManager: Tried connecting socket when engine isn't open. Connecting
2018-04-03 23:57:53.460806+0400 SwiftIPhone[36986:1390892] LOG SocketManager: Adding engine
2018-04-03 23:57:53.461624+0400 SwiftIPhone[36986:1390892] LOG SocketManager: Manager is being released
2018-04-03 23:57:53.461840+0400 SwiftIPhone[36986:1390892] LOG SocketIOClient{/anon}: Client is being released
2018-04-03 23:57:53.461690+0400 SwiftIPhone[36986:1390985] LOG SocketEngine: Starting engine. Server: ws://localhost:5000/
2018-04-03 23:57:53.462246+0400 SwiftIPhone[36986:1390985] LOG SocketEngine: Handshaking
2018-04-03 23:57:53.465429+0400 SwiftIPhone[36986:1390985] LOG SocketEnginePolling: Doing polling GET http://localhost:5000/socket.io/?transport=polling&b64=1
2018-04-03 23:57:53.565013+0400 SwiftIPhone[36986:1391095] LOG SocketEnginePolling: Got polling response
2018-04-03 23:57:53.568265+0400 SwiftIPhone[36986:1391095] LOG SocketEnginePolling: Got poll message: 109:0{"sid":"8c929048a4444954b893b60753f10cde","pingTimeout":60000,"pingInterval":25000,"upgrades":["websocket"]}2:40
2018-04-03 23:57:53.582269+0400 SwiftIPhone[36986:1391095] LOG SocketEngine: Got message: 0{"sid":"8c929048a4444954b893b60753f10cde","pingTimeout":60000,"pingInterval":25000,"upgrades":["websocket"]}
2018-04-03 23:57:53.597628+0400 SwiftIPhone[36986:1391095] LOG SocketEngine: Got message: 40
2018-04-03 23:57:53.599035+0400 SwiftIPhone[36986:1391095] LOG SocketEngine: Writing poll:  has data: false
2018-04-03 23:57:53.600181+0400 SwiftIPhone[36986:1391095] LOG SocketEnginePolling: Sending poll:  as type: 2
2018-04-03 23:57:53.603291+0400 SwiftIPhone[36986:1391095] LOG SocketEnginePolling: Created POST string: 1:2
2018-04-03 23:57:53.604570+0400 SwiftIPhone[36986:1391095] LOG SocketEnginePolling: POSTing
2018-04-03 23:57:53.604955+0400 SwiftIPhone[36986:1391095] LOG SocketEngine: Engine is being released

when false

2018-04-03 23:55:22.421797+0400 SwiftIPhone[36889:1387350] LOG SocketManager: Manager is being released. The manager needs to be a propery or global. It's getting released by ARC.

solved! thanks :)

Was this page helpful?
0 / 5 - 0 ratings

Related issues

MD04-TanTan picture MD04-TanTan  路  5Comments

harshanakaru picture harshanakaru  路  4Comments

JordanOsterberg picture JordanOsterberg  路  7Comments

zevarito picture zevarito  路  3Comments

gaetanm picture gaetanm  路  4Comments