Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

使用2.0,如何记录每个sessionID的所有收发日志? #738

Open
loveyeguo opened this issue Jul 16, 2024 · 5 comments
Open

使用2.0,如何记录每个sessionID的所有收发日志? #738

loveyeguo opened this issue Jul 16, 2024 · 5 comments

Comments

@loveyeguo
Copy link

loveyeguo commented Jul 16, 2024

写在哪个地方比较好? 怎么写?
我是这么写的,但感觉不太好,有没有官方推荐写法?

@loveyeguo
Copy link
Author

意思是说,无论我继承哪个IPipelineFilter,我想记录每个sessionID所有的收发日志,存到本地txt中

@loveyeguo
Copy link
Author

在“IAppSession”中,并没有ReceiveAsync之类的方法

@loveyeguo
Copy link
Author

想要一个类似这样的写法:

private void NewRequestReceivedHandler(SuperSocket.SocketBase.IAppSession session, SuperSocket.SocketBase.Protocol.BinaryRequestInfo requestInfo)
{
// 处理接收到的数据
string receivedData = Encoding.UTF8.GetString(requestInfo.Body);
Console.WriteLine($"Received data from session {session.SessionID}: {receivedData}");

// 可以在这里进行数据处理、响应等操作
}

@loveyeguo
Copy link
Author

@kerryjiang

@kerryjiang
Copy link
Owner

kerryjiang commented Aug 8, 2024

这是你需要的吗?

var host = SuperSocketHostBuilder.Create<StringPackageInfo, CommandLinePipelineFilter>()
    .UsePackageHandler(async (session, package) =>
    {
        Console.WriteLine($"Received data from session {session.SessionID}: {package.Text}");
        await Task.Yield();
    })
    .Build();

await host.RunAsync();

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants