GithubHelp home page GithubHelp logo

Comments (3)

wangruoyi1996 avatar wangruoyi1996 commented on August 16, 2024

我定位到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.

wangruoyi1996 avatar wangruoyi1996 commented on August 16, 2024

非Unity环境下是正常的,区别是使用的包的框架不同,非Unity下使用的是.net8的,Unity下使用的是.netstandard2.1的。我试试非Unity下强制改用2.1的包有没有问题

from supersocket.

wangruoyi1996 avatar wangruoyi1996 commented on August 16, 2024

不是包的框架问题,而是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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.