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

ReadLine 问题 #31

Closed
stulzq opened this issue Nov 7, 2019 · 2 comments
Closed

ReadLine 问题 #31

stulzq opened this issue Nov 7, 2019 · 2 comments

Comments

@stulzq
Copy link

stulzq commented Nov 7, 2019

你好,我准备使用你这个组件来重构一个基于Tcp协议的日志收集Server。服务端读取数据是如下写的:

public override void SessionReceive(IServer server, SessionReceiveEventArgs e)
        {
            var pipeStream = e.Stream.ToPipeStream();
            string name = pipeStream.ReadLine();
            Console.WriteLine(name);
            base.SessionReceive(server, e);
        }

就是你Readme中的写法。

服务端采用的是BeetleX,客户端采用的是C# TcpClient对象,我发现如果我在发送数据的时候如果使用“\n”来分隔每条数据,那么服务端的ReadLine就无法正确读取,如果改成 '\r\n'才行,我猜测ReadLine内部应该使用了服务端运行环境的换行符(没看源码只是猜测)。以上测试环境均为Windows 10。

但是我现在有个需求就是部署在Linux下的API Gateway发送过来的日志数据每条的分隔符为'\n',我现在如何解决ReadLine这个问题呢。

@stulzq
Copy link
Author

stulzq commented Nov 7, 2019

看了源码,原来你是写死了 “\r\n”

@stulzq
Copy link
Author

stulzq commented Nov 7, 2019

已解决 pipeStream.TryReadWith("\n", out var data, false)

@stulzq stulzq closed this as completed Nov 7, 2019
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

1 participant