ERROR SocketEnginePolling: Error during long poll request

Viewed 2145
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"]

3 Answers

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.

  1. Check if you are using 'localhost:PORTNUMBER' as your URL. Instead, try using temporary 'https' using ngrok ngrok.

  2. If you insist on using http, try disabling App Transport Security policy in your project's info.plist

  3. Check if you are using a compatible Client(iOS) and Server(Node js, and etc) Socket.io version. You can check compatibility table here.

    • A simple fix is to drop server Socket.io version to 1.x.x.
    • to keep server Socket.io version to 4.x.x (current at the time of this writing) add allowEI03: true option when instantiating the server:
      const io = new Server(httpServer, {
        allowEIO3: true
      });
    
    • If you are making a server using express I suggest this:
      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);
    

upgrade your package version to 16.0.1. This worked for me too!!!

Related