Why is my Socket.IO server not responding to my Firecamp and C# clients?

Viewed 1161

I am trying to set up a very basic Socket.IO server and a .NET / Firecamp client to learn how to send events between the two.

My Javascript Socket.IO server is set up like this:

const
    http = require("http"),
    express = require("express"),
    socketio = require("socket.io");    

const app = express();
const server = http.createServer(app);    
const io = socketio(server);
const SERVER_PORT = 3000;

io.on("connection", () => {
    console.log("Connected");
    io.emit("foo", "123abc");
});

server.listen(SERVER_PORT);

I am able to connect with a simple Socket.IO Javascript file:

const
    io = require("socket.io-client"),
    ioClient = io.connect("http://localhost:3000");

ioClient.on('connect', () => {
    console.log("connected");    
});

When I try to connect with Firecamp or this C# library I never see a connection event fired.

I looked at the default options for the Socket.IO JS client and tried to reproduce them in Firecamp: https://socket.io/docs/v3/client-api/index.html

The most important ones seem to be the Path= /socket.io, ForceNew = True, and Transports = polling, websocket. I decided to remove the polling transport because I kept getting an XHR polling error, but the websocket also times out in both C# and Firecamp.

I have tried connecting to "http://localhost:3000" and just "http://localhost". Here is a screenshot of my Firecamp settings

I am also seeing a similar issue with my C# program

  Quobject.Collections.Immutable.ImmutableList<string> trans = Quobject.Collections.Immutable.ImmutableList.Create<string>("websocket");
            IO.Options options = new IO.Options();
            options.Port = 3000;
            options.Agent = false;
            options.Upgrade = false;
            options.Transports = trans;
            
            client = IO.Socket("http://localhost:3000", options);
            client.On(Socket.EVENT_CONNECT, () =>
            Console.WriteLine("Connected"));

            client.On(Socket.EVENT_CONNECT_ERROR, (Data) => Console.WriteLine("Connect Error: " + Data));
            client.On(Socket.EVENT_CONNECT_TIMEOUT, (Data) => Console.WriteLine("Connect TImeout Error: " + Data));

            client.On(Socket.EVENT_ERROR, (Data) => Console.WriteLine("Error: " + Data));
            client.Connect();

If I only use a websocket transport I timeout in both Firecamp and C#. If I enable polling I receive the below error:

    Error: Quobject.EngineIoClientDotNet.Client.EngineIOException: xhr poll error ---> System.AggregateException: One or more errors occurred. ---> System.Net.WebException: The remote server returned an error: (400) Bad Request.
   at System.Net.HttpWebRequest.GetResponse()
   at Quobject.EngineIoClientDotNet.Client.Transports.PollingXHR.XHRRequest.<Create>b__7_0()
   at System.Threading.Tasks.Task.InnerInvoke()
   at System.Threading.Tasks.Task.Execute()
   --- End of inner exception stack trace ---
   at System.Threading.Tasks.Task.ThrowIfExceptional(Boolean includeTaskCanceledExceptions)
   at System.Threading.Tasks.Task.Wait(Int32 millisecondsTimeout, CancellationToken cancellationToken)
   at Quobject.EngineIoClientDotNet.Client.Transports.PollingXHR.XHRRequest.Create()
   --- End of inner exception stack trace ---

What other configuration settings can I toggle to try to get my Firecamp or C# connection to show up in my JS Server? I am receiving an "XHR Poll error" from the polling transport, and a timeout from the websocket transport. Is there additional debugging info somewhere I can use to determine where my problem lies? I think if I can get the communication working in either Firecamp or C# I should be able to get it working in the other environment.

2 Answers

I am assuming you're using the SocketIO v3 client. Firecamp is only supporting SocketIO v2. But the good news is in just two days Firecamp is going to give support for SocketIO v3 in the new canary release. I'll keep you posted here.


edited on 7th Sep'21

Firecamp is now supporting SocketIO v2, v3, and v4.

As mentioned above, Firecamp isn't optimized yet for the new version of Socket.IO (v4).
so meanwhile you can choose to manually enable compatibility for Socket.IO v2 clients.
All you have to do is to add "allowEIO3: true" (without quotes) as a key:value pair to the option object and pass this object when you create the server.
this will allow you to communicate with the server via Firecamp.

source https://socket.io/docs/v4/server-api/#Server

below you'll find an example for a working socket.io server integrated with express server.

const app = require('express')();
const httpServer = require('http').createServer(app);
const options = {
      allowEIO3: true,
 };
const io = require('socket.io')(httpServer, options);

app.get('/', (req, res) => {
    res.send('home endpoint');
});

io.on('connection', (socket) => {
   socket.on('new-connection', (data) => {
   console.log(socket.id, 'connected');
   socket.broadcast.emit('test-event', { name: data.name });
 });

// when the user disconnects.. perform this
 socket.on('disconnect', () => {
    console.log(`${socket.id} disconnected`);
  });
});

const port = 3000;

httpServer.listen(port, () => {
   console.log(`server running on port ${port}`);
});
Related