-
Notifications
You must be signed in to change notification settings - Fork 100
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
86 changed files
with
1,035 additions
and
1,421 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,37 @@ | ||
# This is a basic workflow to help you get started with Actions | ||
|
||
name: CI | ||
|
||
on: [push] | ||
# Controls when the workflow will run | ||
on: | ||
push: | ||
pull_request: | ||
workflow_dispatch: | ||
|
||
# A workflow run is made up of one or more jobs that can run sequentially or in parallel | ||
jobs: | ||
# This workflow contains a single job called "build" | ||
build: | ||
|
||
# The type of runner that the job will run on | ||
runs-on: windows-latest | ||
defaults: | ||
run: | ||
working-directory: ./src | ||
|
||
|
||
# Steps represent a sequence of tasks that will be executed as part of the job | ||
steps: | ||
- uses: actions/checkout@v1 | ||
- name: MSBuild | ||
run: | | ||
cd "C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\MSBuild\Current\Bin\" | ||
.\MSBuild.exe $Env:GITHUB_WORKSPACE\src\HiSocket.sln | ||
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it | ||
- uses: actions/checkout@v2 | ||
|
||
# Runs a single command using the runners shell | ||
- name: Hello world | ||
run: echo Hello, world! | ||
|
||
- name: Setup .NET SDK | ||
uses: actions/setup-dotnet@v1.7.2 | ||
with: | ||
dotnet-version: 5.0.x | ||
|
||
- name: Build | ||
run: dotnet build --configuration Release |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
.vs | ||
TestResults | ||
bin | ||
obj |
File renamed without changes.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
/*************************************************************** | ||
* Description: Block buffer for reuse array | ||
* | ||
* Documents: https://github.com/hiram3512/HiSocket | ||
* Support: hiramtan@live.com | ||
***************************************************************/ | ||
|
||
using System; | ||
using System.Collections.Generic; | ||
using System.Diagnostics; | ||
using System.Text; | ||
|
||
namespace HiSocket.Tcp.Example | ||
{ | ||
public class ExamplePackage1 : IPackage | ||
{ | ||
public void Pack(byte[] message, IBlockBuffer<byte> sendBuffer) | ||
{ | ||
sendBuffer.WriteAtEnd(message); | ||
} | ||
public void Unpack(IBlockBuffer<byte> receiveBuffer, ref byte[] message) | ||
{ | ||
var length = receiveBuffer.Index; | ||
if (length > 0) | ||
{ | ||
message = receiveBuffer.ReadFromHead(length); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/*************************************************************** | ||
* Description: Block buffer for reuse array | ||
* | ||
* Documents: https://github.com/hiram3512/HiSocket | ||
* Support: hiramtan@live.com | ||
***************************************************************/ | ||
|
||
using System; | ||
using System.Collections.Generic; | ||
using System.Text; | ||
|
||
namespace HiSocket.Tcp.Example | ||
{ | ||
public class ExamplePackage2 : IPackage | ||
{ | ||
public void Pack(byte[] message, IBlockBuffer<byte> sendBuffer) | ||
{ | ||
//消息头,假设用int标识,4字节 | ||
int length = message.Length; | ||
byte[] lengthBytes = BitConverter.GetBytes(length); | ||
sendBuffer.WriteAtEnd(lengthBytes); | ||
sendBuffer.WriteAtEnd(message); | ||
} | ||
public void Unpack(IBlockBuffer<byte> receiveBuffer, ref byte[] message) | ||
{ | ||
//消息头,假设用int标识,4字节 | ||
if (receiveBuffer.Index >= 4) | ||
{ | ||
byte[] lengthBytes = receiveBuffer.TryReadFromHead(4); | ||
int length = BitConverter.ToInt32(lengthBytes, 0); | ||
if (receiveBuffer.Index >= length)//buffer中有足够数据 | ||
{ | ||
receiveBuffer.IncreaseIndex(4);//消息头,假设用int标识,4字节,开始读取消息体 | ||
message = receiveBuffer.ReadFromHead(length); | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/*************************************************************** | ||
* Description: Block buffer for reuse array | ||
* | ||
* Documents: https://github.com/hiram3512/HiSocket | ||
* Support: hiramtan@live.com | ||
***************************************************************/ | ||
|
||
using System; | ||
using HiSocket; | ||
|
||
namespace HiSocket.Tcp.Example | ||
{ | ||
public class ExampleTcpConnection1 | ||
{ | ||
private TcpConnection tcpConnection; | ||
void Main() | ||
{ | ||
var package = new ExamplePackage2(); | ||
tcpConnection = new TcpConnection(package); | ||
tcpConnection.OnConnecting += OnConnecting; | ||
tcpConnection.OnConnected += OnConnected; | ||
tcpConnection.OnReceiveMessage += OnReceiveMessage; | ||
tcpConnection.Connect("127.0.0.1", 999); | ||
} | ||
void OnConnecting() | ||
{ | ||
Console.WriteLine("Connecting"); | ||
} | ||
void OnConnected() | ||
{ | ||
Console.WriteLine("Connected"); | ||
var data = new byte[] { 1, 2, 3 }; | ||
tcpConnection.Send(data); | ||
} | ||
void OnReceiveMessage(byte[] data) | ||
{ | ||
Console.WriteLine("Receive data"); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
/*************************************************************** | ||
* Description: Block buffer for reuse array | ||
* | ||
* Documents: https://github.com/hiram3512/HiSocket | ||
* Support: hiramtan@live.com | ||
***************************************************************/ | ||
|
||
using System; | ||
using System.Collections.Generic; | ||
using System.Text; | ||
|
||
namespace HiSocket.Tcp.Example | ||
{ | ||
public class ExampleTcpConnection2 | ||
{ | ||
private TcpConnection tcpConnection; | ||
void Main() | ||
{ | ||
var package = new ExamplePackage2(); | ||
tcpConnection = new TcpConnection(package); | ||
tcpConnection.OnConnected += OnConnected; | ||
tcpConnection.OnReceiveMessage += OnReceiveMessage; | ||
tcpConnection.OnException += OnException; | ||
tcpConnection.Connect("127.0.0.1", 999); | ||
tcpConnection.Socket.NoDelay = true; | ||
tcpConnection.Socket.SendTimeout = 100; | ||
tcpConnection.Socket.ReceiveTimeout = 200; | ||
} | ||
|
||
void OnConnected() | ||
{ | ||
Console.WriteLine("Connected"); | ||
var data = new byte[] { 1, 2, 3 }; | ||
tcpConnection.Send(data); | ||
} | ||
void OnReceiveMessage(byte[] data) | ||
{ | ||
Console.WriteLine("Receive data"); | ||
} | ||
void OnException(Exception e) | ||
{ | ||
Console.WriteLine(e.ToString()); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>netstandard2.0</TargetFramework> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\HiSocket.Tcp\HiSocket.Tcp.csproj" /> | ||
</ItemGroup> | ||
|
||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>net5.0</TargetFramework> | ||
|
||
<IsPackable>false</IsPackable> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.9.4" /> | ||
<PackageReference Include="MSTest.TestAdapter" Version="2.2.3" /> | ||
<PackageReference Include="MSTest.TestFramework" Version="2.2.3" /> | ||
<PackageReference Include="coverlet.collector" Version="3.0.2" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\HiSocket.Tcp.Example\HiSocket.Tcp.Example.csproj" /> | ||
<ProjectReference Include="..\HiSocket.Tcp\HiSocket.Tcp.csproj" /> | ||
</ItemGroup> | ||
|
||
</Project> |
Oops, something went wrong.