Code Monkey home page Code Monkey logo

beetlex's Introduction

Beetlex framework 👋

high performance socket tcp communication framework, support Unix domain Socket, TLS, HTTP, HTTPS, WebSocket, Gateway, RPC, Redis ... protocols , custom protocols and 1M connections solution

Package Nuget version Download
BeetleX(tcp component)
BeetleX.FastHttpApi(Http/Websocket server component)
BeetleX.Redis(Redis client component)
BeetleX.Http.Clients(Http/Websocket client component)
XRPC(Remote interface invoke)
MQTT(MQTT Server)

BeetleX's tcp, http, websocket, xprc, web, vue ... samples

Web Framework Benchmarks Round 20 in the top 10

beetlex's People

Contributors

beetlex-io avatar dependabot[bot] avatar kim-ssi avatar lduchosal avatar slang25 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

beetlex's Issues

SessionReceive Stream接收到了,但是解析错误

我使用hp-socket的client发送过来数据,但是解析的时候解析不出来,是什么问题呢?

image

class Program: ServerHandlerBase
    {
        private static IServer server;
        static void Main(string[] args)
        {
            
            server = SocketFactory.CreateTcpServer<Program>();
            server.Open();
            Console.Write(server);
            Console.Read();

            Console.WriteLine("Hello World!");
        }

        public override void SessionReceive(IServer server, SessionReceiveEventArgs e)
        {
            string name = e.Stream.ToPipeStream().ReadLine();
            Console.WriteLine("receive:");
            Console.WriteLine(name);
            e.Session.Stream.ToPipeStream().WriteLine("hello" + name);
            e.Session.Stream.Flush();
            base.SessionReceive(server, e);
        }
    }

跨语言的问题

你的例子中,客户端和服务端都是用的beetleX自己的来做的解析和封装.
现在我想建立一个服务端,客户端可能是各种平台各种语言的,
该用什么方式来创建.?
我一直没找到协议解析相关的.
譬如我收到一个字节数组data,
第一个字节是header,第二个字节是功能,第三个字节表示数据长度,第4个字节到N个,表示数据等等
如是创建????

SslStreamX.SyncData method UnhandledException

Create buffer error, maximum number of buffer pools!
at BeetleX.Buffers.BufferPool.CreateBuffer()
at BeetleX.Buffers.BufferPool.Pop()
at BeetleX.Buffers.SslStreamX.SyncData()
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state)
--- End of stack trace from previous location where exception was thrown ---
at System.Threading.ThreadPoolWorkQueue.Dispatch()

Tcp server with 100000 users

First of all thank you for your contribution. I need a tcp server capable of tolerating 100,000 connected users concurrently. Could you give me an example based on your code? I also need to send a response to each of the connected users

ReadLine 问题

你好,我准备使用你这个组件来重构一个基于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这个问题呢。

希望不吝赐教:tcpclient判断与server断开

我子啊用beetleX测试,AsyncTcpClient当server主动断开时(比如sessionTimeOut到期),会接受到并关闭掉;tcpClient当server主动断开时(比如sessionTimeOut到期),还是保持连接状态,下次发送命令才会发现与主机断开。请教下这块该怎么设计呢。当网络断开或者服务端掉线了,tcpClient获知断开。

session send queue overflow! MaxWaitMessages限制问题

我前段时间关注作者的BeetleX组件很久了,因为使用了Bumblebee做netcore的网关转发,特别看重网关配置的管理插件Configuration;同时也发现作者相关的性能呢测试对比,加上开源就没有再自造轮子。昨天产品做集成测试发现压力还不到几百个网关转发请求,就连续出现“session send queue overflow!”的错误,然后中止了连接。

MaxWaitMessages

不知道如何调整,还是不敢轻易使用该组件啊

添加AwaiterClient

现有的异步Client是通过事件来处理方法,添加AwaiterClient类用于支持异步client的

await receive()

来接收消息

client.Read does not exist and data appears cached

First of all client.Read() doesn't exist, so I used client.Receive(), shown in the code below.

However, I keep getting the first thing read from the server every time, but the server is sending different data on each call.

Is there something I'm doing wrong? Do I need to clear out a buffer or something?

// send to server
client.Stream.ToPipeStream().WriteLine(Newtonsoft.Json.JsonConvert.SerializeObject(value));
client.Stream.Flush();

// Wait for a response
var reader = client.Receive();
var ret = reader.ToPipeStream().ReadLine();
return ret;

BTW, I use a static client, I don't get a new one each time, which worked fine in the Async version.

SessionReceive中不支持直接获取字节数组内容

需要在SessionReceive中获取设备上传上来的以指定byte[](如:new byte[]{0x0D,0x0A})为分隔的字节数组数据。

public override void SessionReceive(IServer server, SessionReceiveEventArgs e)
{
        //类似于实现ReadBytes(byte[] eof)
        var data= e.Stream.ToPipeStream().ReadBytes(new byte[] { 0x0D, 0x0A });
         //.........
}

然后我在PipeStream.cs添加了如下方法:

  /// <summary>
        /// 读取字节数据
        /// </summary>
        /// <returns></returns>
        public byte[] ReadBytes(int length)
        {
            if (length == 0)
                return new byte[0];
            IBuffer rbuffer;
           //暂时不考虑跨平台的代码兼容
            ArraySegment<byte> data;
            byte[] byteSpan = mCacheBlock;

            //要获取的长度小于缓存固定长度时处理的逻辑
            if (length < mCacheBlockLen)
            {
                rbuffer = GetAndVerifyReadBuffer();
                int freelen = rbuffer.Length - rbuffer.Postion;
                if (freelen > length)
                {
                    data = rbuffer.Read(length);
                    ReadAdvance(length);
                    return data.Array;
                }
            }
            
            int rlen = 0;
            while (length > 0)
            {
                if (length > mCacheBlockLen)
                    rlen = mCacheBlockLen;
                else
                    rlen = length;
                rbuffer = GetAndVerifyReadBuffer();
                int freelen = rbuffer.Length - rbuffer.Postion;
                if (freelen > rlen)
                {
                    data = rbuffer.Read(rlen);
                }
                else
                {
                    data = rbuffer.Read(freelen);
                }

                ReadAdvance(data.Count);
                length -= data.Count;           

            }

            return data.Array;
        }
        /// <summary>
        /// 尝试读取数据
        /// </summary>
        /// <param name="eof">结束标识</param>
        /// <param name="value">读取到的byte[]数据</param>
        /// <param name="returnEof">返回时是否包含结束标识</param>
        /// <returns></returns>
        public bool TryReadWith(byte[] eof, out byte[] value, bool returnEof = false)
        {
            value = new byte[0];
            IndexOfResult result = IndexOf(eof);
            int length = result.Length;
            value = new byte[length];
            if (result.End != null)
            {
                if (result.Start.ID == result.End.ID)
                {
                    if (result.Length < mCacheBlockLen)
                    {
                        Array.Copy(result.Start.Bytes,0, value, 0, length);
                        ReadFree(length);
                    }
                    else
                    {
                        value = ReadBytes(length);
                    }
                }
                else
                {
                    if (returnEof)
                    {
                        value = ReadBytes(result.Length);
                    }
                    else
                    {
                        value = ReadBytes(result.Length - eof.Length);
                        Read(eof, 0, eof.Length);
                    }
                }

                return true;
            }
            return false;
        }

然后在SessionReceive中这样写:

        public override void SessionReceive(IServer server, SessionReceiveEventArgs e)
        {
            byte[] result;
            if (e.Stream.ToPipeStream().TryReadWith(new byte[] { 0x0D, 0x0A },out result,true))
            {
                if (result[0] == 0xFA && result.Length == 14 )
                {
                    Console.WriteLine("获取得到了设备代码数据!");
                }
            }
           
        }

Demo 的问题

private Type GetType(string typeName)
{
Type result;
if (!mNameTypes.TryGetValue(typeName, out result))
{
if (typeName == null)
throw new BXException("{0} type not found!", typeName);
result = Type.GetType(typeName);
if (result == null)
throw new BXException("{0} type not found!", typeName);

            mNameTypes[typeName] = result;
        }
        return result;
    }

这一句 是不是有点多余

if (typeName == null)
throw new BXException("{0} type not found!", typeName);

ConcurrentDictionary<string, Type> 好像不能把null 当key

Create buffer error, maximum number of buffer pools!

BeetleX 版本1.3.2
BeetleX demo默认设置
[11:01:40] [Error] session [::ffff:127.0.0.1]:57980@38 error receive data completed SocketError Success!@create buffer error, maximum number of buffer pools!
at BeetleX.Buffers.BufferPool.CreateBuffer()
at BeetleX.Buffers.BufferPool.Pop()
at BeetleX.TcpServer.BeginReceive(ISession session)
at BeetleX.TcpServer.ProcessReceiveArgs(SocketAsyncEventArgs e)
at BeetleX.TcpServer.ReceiveCompleted(SocketAsyncEventArgs e)
使用TCP_UDP_PerformanceTest测试,只开一个连接的情况下持续发送数据,一段时间后BeetleX 也报错,debug下BufferPool里的mCount计数一直累加,直到超过mMaxCount

关于TCP压力测试问题

您好!我在使用你的工具对我的TCPServer进行测试过程中有个问题:创建1000 Client,每隔1s发送。我发送20s后,就关闭连接。针对有应答的测试模式,那么Server的消息还没来得急应答client就关闭了,这样是否也能表征出server的性能呢?谢谢

Listening in the TcpClient

In the AsyncTcpClient, listening is via the client.DataReceive event.

I would prefer to use the async version, but I can't await for a result, if there's a way, I'd like to know.

If not, is there a way to listen for data coming from the server in the TcpClient?

Operation is not valid due to the current state of the object

SpanJson.JsonSerializer.NonGeneric.Utf8.SerializeToArrayPool(data)
报错:
Operation is not valid due to the current state of the object
堆栈:
at lambda_method(Closure , JsonWriter1& , MsgType ) at SpanJson.Formatters.EnumStringFormatter3.Serialize(JsonWriter1& writer, T value) in C:\projects\spanjson\SpanJson\Formatters\EnumStringFormatter.cs:line 23 at lambda_method(Closure , JsonWriter1& , MessageContent )
at SpanJson.Formatters.ComplexClassFormatter3.Serialize(JsonWriter1& writer, T value) in C:\projects\spanjson\SpanJson\Formatters\ComplexClassFormatter.cs:line 32
at lambda_method(Closure , Object )
at SpanJson.JsonSerializer.NonGeneric.Inner`2.InnerSerializeToByteArrayPool(Object input) in C:\projects\spanjson\SpanJson\JsonSerializer.NonGeneric.cs:line 68
at SpanJson.JsonSerializer.NonGeneric.Utf8.SerializeToArrayPool(Object input) in C:\projects\spanjson\SpanJson\JsonSerializer.NonGeneric.cs:line 485
at BeetleXServer.Models.JsonPacket.OnWrite(ISession session, Object data, PipeStream stream) in L:\VSDemo\NetCoreBeetleXServer\BeetleXServer\BeetleXServer\Models\JsonPacket.cs:line 40
at BeetleX.Packets.FixedHeaderPacket.OnEncode(ISession session, Object data, Stream stream)
at BeetleX.Packets.FixedHeaderPacket.Encode(Object data, ISession session, Stream stream)
at BeetleX.TcpSession.WriterData(Object data, Stream stream)
at BeetleX.TcpSession.ProcessSendMessages()
at BeetleX.TcpSession.Send(Object data)
at BeetleX.TcpServer.Send(Object data, ISession session)

SessionReceive 接收问题

TcpClient client = SocketFactory.CreateClient("127.0.0.1", 9090);
client.Stream.ToPipeStream().WriteLine("aaaaaaaa");
client.Stream.Flush();
//System.Threading.Thread.Sleep(100);
client.Stream.ToPipeStream().WriteLine("bbbbbbb");
client.Stream.Flush();

在服务端第一次启动时,客户端连续发送两条数据必须sleep,否则服务端只能收到一条;奇怪的是在不关闭服务端的情况下,再次启动客户端即使没有sleep也能正常收到两条数据的。

关于ServerGC的问题

在使用FasthttpAPI时候 都会报一个
[11:27:55] [Warring] no serverGC mode,please enable serverGC mode!
请问这个是服务器没有开启资源回收么?这种情况是否会有内存泄漏的问题。另外如果要开的话如何开启呢。

现在版本不支持https 吗?

1、https 协议请求报 400 The plain HTTP request was sent to HTTPS port
2、可以在接口列表中显示描述或接口名称,因为现在显示的是url 如果接口比较多 查找某一个接口会不方便
3、接口返回的json数据可以显示为格式化后的json数据

naming convention in example of TCP.SSL

Why did you break your own naming logic?

See line 23
in master/samples/TCP.SSL/Messages/JsonPacket.cs
you wrote
protected override object OnReader(ISession session, PipeStream stream)
but it should be
protected override object OnRead(ISession session, PipeStream stream)

Example of TCP.SSL

Hello!

See line 26 in
master/samples/TCP.SSL/Client/Program.cs

it should be
register.Password = Console.ReadLine();
not register.City

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.