Skip to content

Commit

Permalink
修复postman在ssl下,一直发送消息服务端不能收到的问题;
Browse files Browse the repository at this point in the history
  • Loading branch information
zhuovi committed Aug 22, 2023
1 parent 0d3678b commit 1092f49
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 13 deletions.
23 changes: 19 additions & 4 deletions Net/SocketClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -841,7 +841,7 @@ public virtual async Task<byte[]> ReceviceMessageAsync()
{
try
{
readsize = await stream.ReadAsync(dataBuffer, 0, this.ReceiveBufferSize, this.CancelToken.Token);
readsize = await stream.ReadAsync(dataBuffer, 0, this.ReceiveBufferSize, this.CancelToken.Token).ConfigureAwait(false);
await buffer.WriteAsync(dataBuffer, 0, readsize, this.CancelToken.Token);
}
catch (SocketException ex)
Expand All @@ -868,6 +868,7 @@ public virtual async Task<byte[]> ReceviceMessageAsync()
this.OnClientError?.Invoke(this, this.EndPoint, ex);
break;
}
await Task.Delay(1).ConfigureAwait(false);
} while (readsize > 0 && this.GetStream().DataAvailable);

if (buffer.Length == 0) return Array.Empty<byte>();
Expand Down Expand Up @@ -923,8 +924,7 @@ public virtual async Task ReceviceDataAsync()
this.OnAuthentication?.Invoke(this, msg, EventArgs.Empty);
break;
}
if (this.IsServer)
this.OnStart?.Invoke(this, EventArgs.Empty);

if (this.ConnectionType == ConnectionType.WebSocket)
{
//开始握手
Expand All @@ -945,8 +945,13 @@ public virtual async Task ReceviceDataAsync()
}

FirstConnectMessage = false;
this.OnStart?.Invoke(this, EventArgs.Empty);
continue;
}
else
{
this.OnStart?.Invoke(this, EventArgs.Empty);
}
}
if (!this.IsAuthenticated.HasValue || !this.IsAuthenticated.GetValueOrDefault())
{
Expand All @@ -971,6 +976,12 @@ public virtual async Task ReceviceDataAsync()
SendPongAsync().ConfigureAwait(false);
if (bytes.Length == 0) continue;
}
/*
* 2023-08-23 20:43 Jacky
* Postman 在ssl下 连续发消息接收不到,只能通过回应一个pong来解决
*/
if (this.Certificate != null)
await this.SendPongAsync().ConfigureAwait(false);
}
ReceiveMessage = this.DataType == SocketDataType.String ? bytes.GetString(this.Encoding) : bytes.ByteToHexString();

Expand Down Expand Up @@ -1080,7 +1091,8 @@ private int NetStreamSend(byte[] buffers, OpCode opCode = OpCode.Text)
}
else
{

if (buffers == null || buffers.Length == 0)
return 0;
}
stream.Write(buffers, 0, buffers.Length);
stream.Flush();
Expand All @@ -1107,6 +1119,9 @@ private async Task<int> NetStreamSendAsync(byte[] buffers, OpCode opCode = OpCod
using (var packet = new WebSocketPacket(this))
buffers = packet.Packet(buffers, opCode);
}
else
if (buffers == null || buffers.Length == 0)
return await Task.FromResult(0);
await stream.WriteAsync(buffers, 0, buffers.Length, this.CancelToken.Token);
await stream.FlushAsync(this.CancelToken.Token);
return await Task.FromResult(buffers.Length);
Expand Down
18 changes: 11 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,45 +31,49 @@ XiaoFeng generator with [XiaoFeng](https://github.com/zhuovi/XiaoFeng).
.NET CLI

```
$ dotnet add package XiaoFeng --version 4.0.2
$ dotnet add package XiaoFeng --version 4.0.3
```

Package Manager

```
PM> Install-Package XiaoFeng -Version 4.0.2
PM> Install-Package XiaoFeng -Version 4.0.3
```

PackageReference

```
<PackageReference Include="XiaoFeng" Version="4.0.2" />
<PackageReference Include="XiaoFeng" Version="4.0.3" />
```

Paket CLI

```
> paket add XiaoFeng --version 4.0.2
> paket add XiaoFeng --version 4.0.3
```

Script & Interactive

```
> #r "nuget: XiaoFeng, 4.0.2"
> #r "nuget: XiaoFeng, 4.0.3"
```

Cake

```
// Install XiaoFeng as a Cake Addin
#addin nuget:?package=XiaoFeng&version=4.0.2
#addin nuget:?package=XiaoFeng&version=4.0.3
// Install XiaoFeng as a Cake Tool
#tool nuget:?package=XiaoFeng&version=4.0.2
#tool nuget:?package=XiaoFeng&version=4.0.3
```

# 更新日志

## 2023-08-22 v 4.0.3

1.修复postman在ssl下,一直发送消息服务端不能收到的问题;

## 2023-08-22 v 4.0.2

1.ParameterCollection类增加GetBytes方法,增加多种构造器可以设置是否URL编码及字符串编码;
Expand Down
4 changes: 2 additions & 2 deletions XiaoFeng.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<Copyright>CopyRight @ 2008-2024 魔法精灵(www.eelf.cn) QQ:7092734 Email:jacky@eelf.cn</Copyright>
<Company>魔法精灵</Company>
<VersionPrefix>4.0</VersionPrefix>
<VersionSuffix>2</VersionSuffix>
<VersionSuffix>3</VersionSuffix>
<Version>$(VersionPrefix).$(VersionSuffix)</Version>
<FileVersion>$(Version)</FileVersion>
<AssemblyVersion>$(VersionPrefix)</AssemblyVersion>
Expand All @@ -24,7 +24,7 @@
<PackageProjectUrl>https://www.eelf.cn</PackageProjectUrl>
<PackageIconUrl>http://nuget.fayelf.com/x.png</PackageIconUrl>
<PackageTags>XiaoFeng;FAYELF;DataHelper;HttpHelper;Redis;Socket;Ftp;JSON;XML;</PackageTags>
<PackageReleaseNotes>ParameterCollection类增加GetBytes方法,增加多种构造器可以设置是否URL编码及字符串编码;增加扩展RSAEncryption算法SignHash,VerifyHash;修复Json,Xml中类型为可空枚举时,应该序列化成key则序列化成value的bug;优化Redis关闭;</PackageReleaseNotes>
<PackageReleaseNotes>修复postman在ssl下,一直发送消息服务端不能收到的问题;</PackageReleaseNotes>
<PackageReadmeFile>README.md</PackageReadmeFile>
<PackageLicenseFile>LICENSE</PackageLicenseFile>
<DelaySign>False</DelaySign>
Expand Down

0 comments on commit 1092f49

Please sign in to comment.