Coder Social home page Coder Social logo

Comments (5)

doghappy avatar doghappy commented on August 18, 2024

If the connection is disconnected by the server, the OnClosed event will be called and the parameter value is ClosedByServer. If the server process exits, the OnClosed event will be called too and the parameter value is Aborted.

According to your description, I can't reproduce it. I would be very grateful if you can help me with it.

I used the code to test it and the test results were successful.

server

io.on('connection', client => {
    client.on('close', data => {
        if (data === "close") {
            client.disconnect();
        }
    });
    client.on('disconnect', () => {
        console.log(`disconnect: ${client.id}`);
    });
});
console.log('Socket IO server started');

client

static async Task Main(string[] args)
{
    var client = new SocketIO("http://localhost:3000");
    client.OnClosed += reason => Console.WriteLine(reason);
    client.OnConnected += () =>
    {
        Console.WriteLine("Connected");
    };

    await client.ConnectAsync();
    await Task.Delay(1000);
    await client.EmitAsync("close", "close");
    Console.ReadLine();
}

result

image

from socket.io-client-csharp.

farzadi avatar farzadi commented on August 18, 2024

Yes, I test your code and it's work. but what if my server gets down? how your implementation can handle it and client understand the connection is lost and the server is not available after connection?

from socket.io-client-csharp.

doghappy avatar doghappy commented on August 18, 2024

In general, if the connection is closed by server, the server will return a specific code number(reason = ClosedByServer). But there is still a thread that polls for server status(reason = Aborted)

from socket.io-client-csharp.

farzadi avatar farzadi commented on August 18, 2024

Right, I tested in a console application and it's work. I think it has a problem when running in unity. in unity, can't get the "Aborted" message

from socket.io-client-csharp.

farshid1 avatar farshid1 commented on August 18, 2024

@farzadi Can you share your sample code for connecting to unity? We are having a difficult time setting that up.

from socket.io-client-csharp.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.