Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to use this library in a C# .NET project #343

Open
chrish2 opened this issue Oct 17, 2023 · 6 comments
Open

How to use this library in a C# .NET project #343

chrish2 opened this issue Oct 17, 2023 · 6 comments

Comments

@chrish2
Copy link

chrish2 commented Oct 17, 2023

I am kinda new to the C# and .NET. I installed this package in the Nuget, and I copy and paste the example code from the Readme.
I import the SocketIO and SocketIOClient in my program. However, It DOES NOT work. Could you provide a very simple example c# code that I can directly run without too many changes?

Am I correct to install this package from Nuget ? or if there are any other ways to put this library in to a project (Since I am new to C#)? Which one should I import to my project (SocketIO or SocketIOClient)Thank you.

@JerkoLannoo
Copy link

JerkoLannoo commented Oct 20, 2023

This doesn't work because there are 2 namespaces:

  • one with the name "SocketIO"
  • and one with the name "SocketIOClient", containing a class called "SocketIO", which they are referring to in the "Quick Start" section.
    If you use the name "SocketIO", C# thinks you are referring to the namespace, which is not possible. You need to specify the namespace (SocketIOClient) and then the class name (SocketIO), like this:
    var client = new SocketIOClient.SocketIO("http://server_address:port/");
    Hope this helps.
    (edited because of grammar error)

@chrish2
Copy link
Author

chrish2 commented Nov 24, 2023

Thank you and this works! Are there any c# project in Github that uses SocketIOClient? I just want to learn how to use it from a well written project instead of I try hundreds times to let it work. Thank you.

@NandishNR
Copy link

This doesn't work because there are 2 namespaces:

  • one with the name "SocketIO"
  • and one with the name "SocketIOClient", containing a class called "SocketIO", which they are referring to in the "Quick Start" section.
    If you use the name "SocketIO", C# thinks you are referring to the namespace, which is not possible. You need to specify the namespace (SocketIOClient) and then the class name (SocketIO), like this:
    var client = new SocketIOClient.SocketIO("http://server_address:port/");
    Hope this helps.
    (edited because of grammar error)

I have followed the same but notning is working. Execution goes inside ConnectAsync will not come out only.

@JerkoLannoo
Copy link

I have followed the same but notning is working. Execution goes inside ConnectAsync will not come out only.

What do you mean? What error do you get?

@NandishNR
Copy link

NandishNR commented May 8, 2024

@chrish2 , @JerkoLannoo

  1. Server package version: "https://www.npmjs.com/package/socket.io/v/2.5.0"
  2. Client package version: Latest version, 2.0.0, 2.3.0,3.0.0, etc..
  3. Client built using .Net 6.0
  4. Able to build connection using postman
  5. Checked Wireshark logs as well - nothing blocked on laptop like antivirus or proxy

Below is the code, where not able to build connection and execution will not comeout from "await _socketIO.ConnectAsync();". Connected flag is false and not able emit the message.

SocketIOOptions options = new SocketIOOptions();
options.Path = SocketPath;
options.Query = new List<KeyValuePair<string, string>>
{
new KeyValuePair<string, string>("token", Accesstoken),
new KeyValuePair<string, string>("deviceId", DeviceId)
};
options.Transport = SocketIOClient.Transport.TransportProtocol.WebSocket;
options.Reconnection = true;
options.ReconnectionDelayMax = 10;
options.ReconnectionDelay = 1000;
options.ConnectionTimeout = TimeSpan.FromMilliseconds(10000);

Uri uri = new Uri(SocketUri);
SocketIOClient.SocketIO _socketIO = new SocketIOClient.SocketIO(uri, options);
_socketIO.OnConnected += OnSocketIOConnected;
_socketIO.OnReconnected += OnSocketIOReconnected;
_socketIO.OnError += OnSocketIOError;
await _socketIO.ConnectAsync();

@NandishNR
Copy link

NandishNR commented May 13, 2024

Hi @chrish2 , @JerkoLannoo,

Upgraded sever to latest package and able to connect .net client. However, what ever sever emit the events .net client is not received but received in react client.

Any inputs on this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants