Company logo
  • Jobs
  • Bootcamp
  • About Us
  • For professionals
    • Home
    • Jobs
    • Courses
    • Questions
    • Teachers
    • Bootcamp
  • For business
    • Home
    • Our process
    • Plans
    • Assessments
    • Payroll
    • Blog
    • Calculator

0

107
Views
Javascript Code for Socketio Doesn't Work on C#

The problem is as the title says, I got the Nugget package for Socket.io on C#, then the tried moving same code that I have working on Javascript to it, and it doesn't work on C#. I'm new to WebSockets so I'd appreciate any help.

Here's the Javascript code that works:

const io = require('socket.io-client');

//function
async function initSocket() {
    //define socket
    const socket = io(
        "wss://trade.csgoempire.com/trade", {
            transports: ["websocket"],
            path: "/s/",
            extraHeaders: { 'User-agent': `test API Bot` }
        }
    );
    //connect event
    socket.on('connect', async() => {
        console.log(`Connected to websocket`);
        //log new items
        socket.on('new_item', (data) => console.log(`new_item`));
        socket.on('deleted_item', (data) => console.log(`deleted_item`));
    });
};
//run function
initSocket();

And here's the C# code that doesn't:

//define socket
var SIO = new SocketIO("wss://trade.csgoempire.com/trade/", new SocketIOOptions()
     {
     EIO = 3,
     Transport = SocketIOClient.Transport.TransportProtocol.WebSocket,
     Path = "/s/",
     ExtraHeaders = new Dictionary<string, string> { { "User-agent", "Test API Bot" } }
     });
    
//connect event
SIO.On("connect", async (connectData) =>
     {
     Console.WriteLine("Connected to Websocket");
    
     SIO.On("new_item", (data) => Console.WriteLine("new_item"));
     SIO.On("deleted_item", (data) => Console.WriteLine("deleted_item"));
     });

Moving the whole project to JS is indeed an option but I'm just really frustrated and can't figure out what I'm doin wrong.

6 months ago · Santiago Gelvez
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post job Plans Our process Sales
Legal
Terms and conditions Privacy policy
© 2023 PeakU Inc. All Rights Reserved.