SocketIOSharp 1.0.2
See the version list below for details.
Requires NuGet 2.12 or higher.
dotnet add package SocketIOSharp --version 1.0.2
NuGet\Install-Package SocketIOSharp -Version 1.0.2
<PackageReference Include="SocketIOSharp" Version="1.0.2" />
<PackageVersion Include="SocketIOSharp" Version="1.0.2" />
<PackageReference Include="SocketIOSharp" />
paket add SocketIOSharp --version 1.0.2
#r "nuget: SocketIOSharp, 1.0.2"
#:package SocketIOSharp@1.0.2
#addin nuget:?package=SocketIOSharp&version=1.0.2
#tool nuget:?package=SocketIOSharp&version=1.0.2
SocketIOSharp
SocketIOSharp is a Socket.IO protocol revision 4 client library based on Engine.IO and WebSocket protocol. It depends on WebSocketSharp to use WebSocket protocol. Engine.IO protocol is partly implemented by itself.
Installation
Command
Install-Package SocketIOSharpin nuget package manager console.
Usage
Namespace
using SocketIOSharp.Client;
Constructor
SocketIOClient client = new SocketIOClient(SocketIOClient.Scheme.ws, host, port);
SocketIOClient.Scheme
public enum Scheme
{
ws,
wss
}
It is used to determine whether SocketIOClient instance will connect to server using WebSocket protocol or WebSocketSecure protocol.
Options in constructor
public SocketIOClient(SocketIOClient.Scheme Scheme, string Host, int Port, bool JsonOnly = false, bool AutoReconnect = false, bool UseAckTimeout = false)
bool JsonOnlyis used to determine whetherSocketIOClientinstance will or will not acceptWebSocketbinary packet.bool AutoReconnectis used to determine whetherSocketIOClientinstnace will or will not reconnect to server whenWebSocket.OnCloseis called.bool UseAckTimeoutis used to determine whetherSocketIOClientinstnace will or will not automatically remove timed out ack actions.
All options above can be changed after construct like
client.JsonOnly = false. Default value of these arefalse.If
JsonOnlyistrue,SocketIOClientinstance will NOT handleWebSocketbinary packet.If
AutoReconnectistrue,SocketIOClientinstance will reconnect afterWebSocket.OnCloseis called.If
UseAckTimeoutistrue,SocketIOClientinstance will automatically remove timed out ack actions.
Connect
client.Connect();
Disconnect
client.Close();
or
client.Dispose();
Since SocketIOClient implements IDisposable interface, it will be automatically disconnect when SocketIOClient.Dispose is called.
Handlers
For convenient usage, it is implemented to can be used as Javascript style.
Event handlers
client.On(SocketIOClient.Event.CONNECTION, (JToken[] Data) => // Type of argument is JToken[].
{
Console.WriteLine("Connected!");
});
client.On(SocketIOClient.Event.DISCONNECT, (Data) => // Argument can be used without type.
{
Console.WriteLine("Disconnected!");
});
client.On(SocketIOClient.Event.ERROR, (Data) =>
{
if (Data != null && Data.Length > 0 && Data[0] != null)
{
Console.WriteLine("Error : " + Data[0]);
}
else
{
Console.WrtieLine("Unkown Error");
}
});
client.On("message", (Data) =>
{
if (Data != null && Data.Length > 0 && Data[0] != null)
{
Console.WriteLine("Message : " + Data[0]);
}
});
client.On("CustomEvent", CustomEventHandler); // Handler can be method.
client.On(9001, ItsOverNineThousands); // Type of event is JToken. So, it can be a number.
client.Off(9001, ItsOverNineThousands); // Remove 9001 event handler.
ACK handlers
client.On("ACK1", (JToken[] Data, (JToken[] Data) => { Console.WriteLine("ACK : " + Data) } =>
{
// Type of first argument is JToken[].
// Type of second arguemtn is Action<JToken[]>.
Console.Write("On event ack1 : " + Data);
});
client.On("ACK2", (Data, AckAction) => // Second argument can be method.
{
Console.Write("On event ack2 : " + Data);
});
client.On("ACK3", CustomAckHandler); // Handler can be method.
client.On(42, LifeTheUniverseAndTheEverything); // Type of event is JToken. So, it can be a number.
client.Off(42, LifeTheUniverseAndTheEverything); // Remove 42 ack handler.
SocketIOClient.Event
public static class Event
{
public static readonly string CONNECTION = "connection";
public static readonly string DISCONNECT = "disconnect";
public static readonly string ERROR = "error";
}
These are the common basic Socket.IO events.
Emit
client.Emit("Event without data and ack");
client.Emit("Event only with data", "Hello world");
client.Emit("Event only with ack, action as lambda", (Data) => Console.WriteLine("ACK : " + Data));
client.Emit("Event only with ack, action as method", Console.WriteLine);
client.Emit("Event with data and ack, action as lambda", 9001, (Data) => Console.WriteLine("ACK : " + Data));
client.Emit("Event with data and ack, action as method", 42, Console.WriteLine);
// Type of data is JToken. So, it can be a number.
Implemented features
- Fully implemented
Socket.IOprotocol includeshartbeat. See Socket.IO protocol specifications for details. - Partly implemented
Engine.IOprotocol. For now,WebSocketis the ONLY supported transport. And the packet typeupgradeandnoopis NOT supproted. See Engine.IO protocol specifications for details.
Planned features
- Fully implemented
Engine.IOclient (It will implemented as independent project) - Transport without
WebSocket
Limitations
- Partly implemented Engine.IO : It implements part of
Engine.IOonly for processingSocket.IOpacket. Therefore, it can NOT be used asEngine.IOclient. - Only with WebSocket : Since it uses
Websocketas transport, it can be used ONLY whenWebSocketis avalible atSocket.IOserver. - Code style :
SocketIOSharpis written in 2016 by a college student. It can be looked as old or odd style.
Maintenance
Welcome to report issue or create pull request. I will check it happily.
Dependencies
License
SocketIOSharp is under The MIT License.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
| .NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
| .NET Standard | netstandard2.0 is compatible. netstandard2.1 was computed. |
| .NET Framework | net40 is compatible. net403 was computed. 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. |
| MonoAndroid | monoandroid was computed. |
| MonoMac | monomac was computed. |
| MonoTouch | monotouch was computed. |
| Tizen | tizen40 was computed. tizen60 was computed. |
| Xamarin.iOS | xamarinios was computed. |
| Xamarin.Mac | xamarinmac was computed. |
| Xamarin.TVOS | xamarintvos was computed. |
| Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETFramework 4.0
- Newtonsoft.Json (>= 12.0.3)
- WebSocketSharp-NonPreRelease (>= 1.0.0)
-
.NETFramework 4.5
- Newtonsoft.Json (>= 12.0.3)
- WebSocketSharp-NonPreRelease (>= 1.0.0)
-
.NETStandard 2.0
- Newtonsoft.Json (>= 12.0.3)
- WebSocketSharp-netstandard (>= 1.0.1)
NuGet packages (1)
Showing the top 1 NuGet packages that depend on SocketIOSharp:
| Package | Downloads |
|---|---|
|
My.DB.Logger
a small company that publish a csharp creeats and publish library |
GitHub repositories (1)
Showing the top 1 popular GitHub repositories that depend on SocketIOSharp:
| Repository | Stars |
|---|---|
|
MatterHackers/MatterControl
3D printing software for Windows, Mac and Linux
|
Fix bug from critical misunderstanding of ping timeout.