SocketIOClient.NetFx
1.0.0
There is a newer version of this package available.
See the version list below for details.
See the version list below for details.
dotnet add package SocketIOClient.NetFx --version 1.0.0
NuGet\Install-Package SocketIOClient.NetFx -Version 1.0.0
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="SocketIOClient.NetFx" Version="1.0.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add SocketIOClient.NetFx --version 1.0.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: SocketIOClient.NetFx, 1.0.0"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install SocketIOClient.NetFx as a Cake Addin #addin nuget:?package=SocketIOClient.NetFx&version=1.0.0 // Install SocketIOClient.NetFx as a Cake Tool #tool nuget:?package=SocketIOClient.NetFx&version=1.0.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
Socket.IO-client for .NET
An elegant socket.io client for .NET
How to use
Example of usage
Emit an event
Client:
var client = new SocketIO("http://localhost:11000/");
client.On("hi", response =>
{
string text = response.GetValue<string>();
});
client.OnConnected += async (sender, e) =>
{
await client.EmitAsync("hi", ".net core");
};
await client.ConnectAsync();
Server:
socket.on("hi", name => {
socket.emit("hi", `hi ${name}, You are connected to the server`);
});
Emit with Ack
Client:
var client = new SocketIO("http://localhost:11000/");
client.OnConnected += async (sender, e) =>
{
await client.EmitAsync("ack", response =>
{
result = response.GetValue();
}, ".net core");
};
await client.ConnectAsync();
Server:
socket.on("ack", (name, fn) => {
fn({
result: true,
message: `ack(${name})`
});
});
Emit with Binary
Client:
var client = new SocketIO("http://localhost:11000/");
client.OnConnected += async (sender, e) =>
{
await client.EmitAsync("bytes", name, new
{
source = "client001",
bytes = Encoding.UTF8.GetBytes(".net core")
});
};
client.On("bytes", response =>
{
var result = response.GetValue<ByteResponse>();
});
await client.ConnectAsync();
class ByteResponse
{
public string ClientSource { get; set; }
public string Source { get; set; }
[JsonProperty("bytes")]
public byte[] Buffer { get; set; }
}
Server:
socket.on("bytes", (name, data) => {
const bytes = Buffer.from(data.bytes.toString() + " - server - " + name, "utf-8");
socket.emit("bytes", {
clientSource: data.source,
source: "server",
bytes
});
});
Get multiple response values
Client:
var client = new SocketIO("http://localhost:11000/");
client.OnConnected += async (sender, e) =>
{
await client.EmitAsync("change", new
{
code = 200,
message = "val1"
}, "val2");
};
client.On("change", response =>
{
// You can get the JSON string of the response by calling response.ToString()
// After that you can decide how to parse the response data.
// For example: ["val2", { "code": 200, "message": "val1" }]
string resVal1 = response.GetValue<string>();
ChangeResponse resVal2 = response.GetValue<ChangeResponse>(1);
// If you don't want to create a model, you can parse it like this
string message = response.GetValue(1).Value<string>("message");
int code = response.GetValue(1).Value<int>("code");
// More specific usage: https://github.com/jamesnk/newtonsoft.json
});
await client.ConnectAsync();
class ChangeResponse
{
public int Code { get; set; }
public string Message { get; set; }
}
Server:
socket.on("change", (val1, val2) => {
socket.emit("change", val2, val1);
})
More examples
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET Framework | net45 is compatible. net451 was computed. net452 was computed. net46 was computed. net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
-
- Newtonsoft.Json (>= 12.0.3)
- WebSocketSharpFork (>= 1.0.4)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated | |
---|---|---|---|
2.0.2.10 | 4,155 | 11/9/2020 | |
2.0.2.9 | 1,235 | 10/27/2020 | |
1.0.0.6 | 1,069 | 10/26/2020 | |
1.0.0.5 | 987 | 10/9/2020 | |
1.0.0.4 | 1,345 | 9/9/2020 | |
1.0.0.3 | 4,325 | 9/8/2020 | |
1.0.0.2 | 1,030 | 9/8/2020 | |
1.0.0.1 | 1,040 | 8/14/2020 | |
1.0.0.1-alpha | 873 | 8/11/2020 | |
1.0.0 | 1,080 | 7/24/2020 | |
1.0.0-alpha3 | 889 | 6/16/2020 | |
1.0.0-alpha2 | 911 | 6/16/2020 | |
1.0.0-alpha1 | 914 | 6/16/2020 |