socket.core 1.0.1

There is a newer version of this package available.
See the version list below for details.
dotnet add package socket.core --version 1.0.1
NuGet\Install-Package socket.core -Version 1.0.1
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="socket.core" Version="1.0.1" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add socket.core --version 1.0.1
#r "nuget: socket.core, 1.0.1"
#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 socket.core as a Cake Addin
#addin nuget:?package=socket.core&version=1.0.1

// Install socket.core as a Cake Tool
#tool nuget:?package=socket.core&version=1.0.1

socket.core

This is a socket framework written based on C # standard, the interface design is simple, separate thread operation, does not affect the caller. Can be used in the net Framework 4.x.x / standard assembly, in the window (IOCP) / linux normal operation.

Install NuGet:
Package Manager: Install-Package socket.core
.Net CLI: dotnet add package socket.core
Paket CLI: paket add socket.core

Server socket.core.Server namespace, respectively, three modes push / pull / pack Under the socket.core.
Client namespace of the client, there are three modes of push / pull / pack

The main process and the corresponding methods and events introduced.
Note: connectId (guid) represents a connection object, data (byte []), success (bool)
  

    1. Initialize socket (corresponding to the three modes)

Instantiate the server class TcpPushServer / TcpPullServer / TcpPackServer
Instantiate the client class TcpPushClient / TcpPullClient / TcpPackClient

    1. Start monitoring / connecting server

Server server.Start (port);
Client client.Connect (ip, port);

    1. Trigger the connection event

Server server.OnAccept (connectId); Received a connection id, can be used to send, receive, close the tag
Client client.OnAccept (success); Receives whether to connect to the server successfully

    1. Send a message

Server server.Send (connectId, data, offset, length);
Client client.Send (data, offset, length);

    1. Triggered receive events

Server server.OnReceive (connectId, data);
Client client.OnReceive (data);

    1. Close the connection

Server server.Close (connectId);
Client client.Close ();

    1. Trigger to close the connection event

Server server.OnClose (connectId);
Client client.OnClose ();

Three models introduction

  • One: push
        > Will trigger the monitor event object OnReceive (connectId, data); the data immediately "pushed" to the application
  • Two: pull
        > OnReceive (connectId, length), which tells the application how much data has been received. The application checks the length of the data. If it meets, it calls the Fetch (connectId, length) method of the component, Data "pulled" out
  • Three: pack
        > pack The model component is a combination of the push and pull models. The application does not have to deal with subcontracts. The component guarantees that every application server.OnReceive (connectId, data) /client.OnReceive (data) event provides the application with a Complete data package Note: The pack model component automatically adds a 4-byte (32-bit) header to each packet sent by the application. When the component receives the data, it is automatically packetized based on the header information. Each complete packet is sent to OnReceive The event is sent to the application PACK header format
    XXXXXXXXXXYYYYYYYYYYYYYYYYYYYYYY
    The first 10 X bits are the header identification bits, which are used for data packet verification. The effective header identification value ranges from 0 to 1023 (0x3FF). When the header identification equals 0, the header is not checked. The last 22 bits of Y are length bits. Package length. The maximum valid packet length can not exceed 4194303 (0x3FFFFF) bytes (bytes), the application can be set by the TcpPackServer / TcpPackClient constructor parameter headerFlag

2017/12/27

socket.core

这是一个基于C# standard 写的socket框架,接口设计简单,单独线程运行,不影响调用方。可使用于net Framework 4.x.x/standard程序集,能在window(IOCP)/linux正常运行.

安装NuGet:
Package Manager: Install-Package socket.core
.Net CLI :dotnet add package socket.core
Paket CLI:paket add socket.core

服务端所在socket.core.Server命名空间下,分别为三种模式 push/pull/pack
客户端所在socket.core.Client命名空间下,分别为三种模式 push/pull/pack

主要流程与对应的方法和事件介绍.
注:connectId(guid)代表着一个连接对象,data(byte[]),success(bool)

  • 1.初始化socket(对应的三种模式)

    实例化服务端类 TcpPushServer/TcpPullServer/TcpPackServer
    实例化客户端类 TcpPushClient/TcpPullClient/TcpPackClient

  • 2.启动监听/连接服务器

    服务端 server.Start(port);
    客户端 client.Connect(ip,port);

  • 3.触发连接事件

    服务端 server.OnAccept(connectId); 接收到一个连接id,可用他来发送,接收,关闭的标记
    客户端 client.OnAccept(success); 接收是否成功连接到服务器

  • 4.发送消息

    服务端 server.Send(connectId,data,offset,length);
    客户端 client.Send(data,offset,length);

  • 5.触发接收事件

    服务端 server.OnReceive(connectId, data);
    客户端 client.OnReceive(data);

  • 6.关闭连接

    服务端 server.Close(connectId);
    客户端 client.Close();

  • 7.触发关闭连接事件

    服务端 server.OnClose(connectId);
    客户端 client.OnClose();

三种模型简介

  • 一:push

    会触发监听事件对象OnReceive(connectId,data);把数据立马“推”给应用程序

  • 二:pull

    到数据时会触发监听事件对象OnReceive(connectId,length),告诉应用程序当前已经接收到了多少数据,应用程序检查数据的长度,如果满足则调用组件的Fetch(connectId,length)方法,把需要的数据“拉”出来

  • 三:pack

    pack模型组件是push和pull模型的结合体,应用程序不必要处理分包/合包,组件保证每个server.OnReceive(connectId,data)/client.OnReceive(data)事件都向应用程序提供一个完整的数据包
    注:pack模型组件会对应用程序发送的每个数据包自动加上4个字节(32位)的包头,组件接收到数据时,根据包头信息自动分包,每个完整的数据包通过OnReceive事件发送给应用程序
    PACK包头格式
    XXXXXXXXXXYYYYYYYYYYYYYYYYYYYYYY
    前10位X为包头标识位,用于数据包校验,有效包头标识取值范围0~1023(0x3FF),当包头标识等于0时,不校验包头,后22位Y为长度位,记录包体长度。有效数据包最大长度不能超过4194303(0x3FFFFF)字节(byte),应用程序可以通过TcpPackServer/TcpPackClient构造函数参数headerFlag设置

    2017/12/27

Product 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. 
.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 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • .NETStandard 2.0

    • No dependencies.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on socket.core:

Package Downloads
Centralized.Micro.Service.Core

Package Description

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.0.16 894 11/1/2022
1.0.15 765 10/30/2022
1.0.14 12,502 12/3/2018
1.0.13 2,208 2/7/2018
1.0.12 1,773 1/29/2018
1.0.11 1,734 1/18/2018
1.0.10 1,742 1/16/2018
1.0.9 1,690 1/15/2018
1.0.8 1,695 1/12/2018
1.0.7 1,767 1/11/2018
1.0.6 1,753 1/10/2018
1.0.5 1,757 1/4/2018
1.0.4 1,791 1/4/2018
1.0.3 1,705 1/2/2018
1.0.2 1,808 1/1/2018
1.0.1 1,945 1/1/2018
1.0.0 2,010 12/29/2017

socket.core