Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ERROR SocketEnginePolling: Error during long poll request

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

like image 408
Shankar Thorve Avatar asked Jun 24 '20 18:06

Shankar Thorve


Video Answer


2 Answers

update pod to Socket.IO-Client-Swift 16.0.1

like image 191
Eman Gaber Avatar answered Oct 14 '22 07:10

Eman Gaber


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);
    
like image 43
Hitit Avatar answered Oct 14 '22 06:10

Hitit