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

Shankar Thorve
  • 131
  • 2
  • 6
  • Check your server logs and when the swift-client connects look for a message, "The client is using an unsupported version of the Socket.IO or Engine.IO protocols". If you see this message, update Socket.io-Swift-Client to the latest version. This fixed the issue for me. – Eric Feb 11 '21 at 17:19

3 Answers3

8

update pod to Socket.IO-Client-Swift 16.0.1

Eman Gaber
  • 81
  • 1
  • 2
  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Jan 11 '22 at 15:30
  • @Eman Gaber its work for me thanks – Harshil Kotecha Feb 12 '22 at 16:48
2

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);
    
Hitit
  • 420
  • 6
  • 21
0

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

  • As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Vikram Parimi Sep 16 '22 at 12:22