Comments (3)
我定位到PipeConnection里的FillPipeAsync这一处
var memory = writer.GetMemory(bufferSize);接收数据前,获取了pipe里的_writingHeadMemory
提取memory的array传给socket的BeginReceive函数
var bytesRead = await FillPipeWithDataAsync(memory, cancellationToken).ConfigureAwait(false);
接收数据后,socket的BeginReceive里的buffer有正确的数据,返回的size也是对的。
这里获取到的bytesRead是正确的,但是memory变成了一个length为0的对象,pipe里的_writingHeadMemory
依旧是length为4096的对象,但数据全是0,和接收数据前一样。
理论上socket的BeginReceive里的buffer就是_writingHeadMemory内部的array,应该会同步改变,问题就出现在这里
if (bytesRead == 0)
{
if (!CloseReason.HasValue)
CloseReason = Connection.CloseReason.RemoteClosing;
break;
}
顺便补充下,我用的SuperSocket的版本是2.0.0-beta.20.448
from supersocket.
非Unity环境下是正常的,区别是使用的包的框架不同,非Unity下使用的是.net8的,Unity下使用的是.netstandard2.1的。我试试非Unity下强制改用2.1的包有没有问题
from supersocket.
不是包的框架问题,而是unity mono框架和.net的不一样,出问题的是Socket的异步接收函数,unity里传入Memory的函数会执行Memory.ToArray,改成传入ArraySegment的函数就可以了。
通过继承TcpPipeConnection重写了ReceiveAsync函数
MemoryMarshal.TryGetArray(memory, out ArraySegment buffer);
return await socket.ReceiveAsync(buffer, socketFlags).ConfigureAwait(false);//改用ArraySegment参数的接收函数
然后继承ConnectionFactoryBuilder重写Build返回新的TcpPipeConnection
最后在创建服务时配置新的ConnectionFactoryBuilder
.ConfigureServices(options =>
{
options.AddSingleton<IConnectionFactoryBuilder, MyConnectionFactoryBuilder>();
})
from supersocket.
Related Issues (20)
- websocket在大量连接下发送数据遇到一个BUG
- How do I get unfiltered raw packets?
- Set Licence type & repo url on package info
- 发布的MyGet Version 下载问题 HOT 2
- Breaking changes were introduced in 2.0 beta.19.429 HOT 2
- 用AsyncTcpSession 来创建客户端连接,有时候会连不上,多久都没有返回结束? HOT 2
- 客户端同时大量发送和接收数据时报错: Writing is not allowed after writer was completed. HOT 8
- 在Unity中启动服务器无效,Unity卡住 HOT 6
- SuperSocket可以在哪些平台中运行
- 请问如何实现一个客户端连接生成一个独立的日志文件? HOT 1
- 请问如何实现一个客户端连接生成一个独立的日志文件? HOT 2
- Several errors in the unit tests in the build pipeline
- NativeAot HOT 3
- UsePackageHandler里收不到数据呢 HOT 1
- 下面的EasyClient发送数据服务端接收不到呢 HOT 4
- 为什么2.0中没有【可允许连接的最大连接数】的配置? HOT 1
- 无法在ICommand使用依赖注入服务 HOT 1
- SuperSocket not working in Xamarin.Forms HOT 1
- 为什么nuget上搜索的结果都是2016年的版本? HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from supersocket.