Coder Social home page Coder Social logo

Comments (7)

doghappy avatar doghappy commented on August 18, 2024

SocketIO.State is always None, the possible reason is: not connected to the server yet

When the data returned by the server starts with 40, it indicates that the connection is successfully established.

https://github.com/socketio/socket.io-protocol#packet

Related code:

private void ConnectHandler()
{
State = SocketIOState.Connected;
OnConnected?.Invoke();
}

class ConnectedParser : Parser
{
public override void Parse(ParserContext ctx, ResponseMessage resMsg)
{
if (resMsg.Text == "40" + ctx.Namespace)
{
ctx.ConnectHandler();
}
else if (Next != null)
{
Next.Parse(ctx, resMsg);
}
}
}

from socket.io-client-csharp.

bpcuong2013 avatar bpcuong2013 commented on August 18, 2024

Our socket URI is http://<my_ip>:<my_port>/notification

When the data returned by the server starts with 40, the ConnectHandler method is not called because ctx.Namespace is '/Notification,'

image

image

from socket.io-client-csharp.

bpcuong2013 avatar bpcuong2013 commented on August 18, 2024

We also received data that starts with '40/notification', but ConnectHandler is still not called because of missing common character.

image

from socket.io-client-csharp.

doghappy avatar doghappy commented on August 18, 2024

you got 40/notification instead of 40/notification, ?

from socket.io-client-csharp.

bpcuong2013 avatar bpcuong2013 commented on August 18, 2024

Exactly, I got 40/notification

from socket.io-client-csharp.

doghappy avatar doghappy commented on August 18, 2024

You can change the code, add .TrimEnd(",")

 class ConnectedParser : Parser 
 { 
     public override void Parse(ParserContext ctx, ResponseMessage resMsg) 
     { 
         if (resMsg.Text == "40" + ctx.Namespace.TrimEnd(",")) 
         { 
             ctx.ConnectHandler(); 
         } 
         else if (Next != null) 
         { 
             Next.Parse(ctx, resMsg); 
         } 
     } 
 } 

I need to do some related research

from socket.io-client-csharp.

bpcuong2013 avatar bpcuong2013 commented on August 18, 2024

Got it. Thanks for your support!

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.