let manager = SocketManager(socketURL: URL(string: "Some url")!, config: [.log(true), .compress])
var socket:SocketIOClient!
var name: String?
var resetAck: SocketAckEmitter?
override func viewDidLoad() {
super.viewDidLoad()
socket = manager.defaultSocket
socket.on(clientEvent: .connect) {data, ack in
print("socket connected")
}
self.socket.on(clientEvent: .error) {data, ack in
print("error")
}
self.socket?.on(clientEvent: .disconnect){data, ack in
print("disconnect")
}
socket.connect()
}
ERROR SocketEnginePolling: Error during long poll request
LOG SocketIOClient{/}: Handling event: error with data: ["Error"]
update pod to Socket.IO-Client-Swift 16.0.1
So this problem gave me quite an agonizing 8-hour of digging and here are the steps I followed to solve the problem.
Check if you are using 'localhost:PORTNUMBER' as your URL. Instead, try using temporary 'https' using ngrok
ngrok.
If you insist on using http, try disabling App Transport Security policy
in your project's info.plist
Check if you are using a compatible Client(iOS) and Server(Node js, and etc) Socket.io version. You can check compatibility table here.
allowEI03: true
option when instantiating the server: const io = new Server(httpServer, {
allowEIO3: true
});
const express = require("app");
const { createServer } = require("http");
const { Server } = require("socket.io");
const app = express();
const httpServer = createServer(app);
const io = new Server(httpServer, {
allowEIO3: true,
});
io.on("connection", (socket) => {
// ...
});
httpServer.listen(3000);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With