Code Monkey home page Code Monkey logo

Comments (9)

beetlex-io avatar beetlex-io commented on May 17, 2024

如果你了解MQTT那应该很容易,可以看一下samples如何操作网络数据流。
https://github.com/IKende/FastHttpApi 这个http服务也是BeetleX的基础上进行构建的

from beetlex.

fymeng2017 avatar fymeng2017 commented on May 17, 2024

您好,我用sample里面的例子 使用工具测试为啥在server端收不到数据呢?是发送数据格式不对 还是怎么回事。谢谢

from beetlex.

beetlex-io avatar beetlex-io commented on May 17, 2024

那个sample ,发怎样的数据?

from beetlex.

fymeng2017 avatar fymeng2017 commented on May 17, 2024

Echo.Server 用你介绍的TCP/UDP服务性能测试工具 发一段utf文本,server收不到,用Echo.Client 随便发什么都可以接收到,不过好像有长度限制

from beetlex.

fymeng2017 avatar fymeng2017 commented on May 17, 2024

我的意思是在这里不能输出:
public override void SessionReceive(IServer server, SessionReceiveEventArgs e) { string name = e.Stream.ToPipeStream().ReadLine(); Console.WriteLine(name); e.Session.Stream.ToPipeStream().WriteLine("hello " + name); e.Session.Stream.Flush(); base.SessionReceive(server, e); }

from beetlex.

beetlex-io avatar beetlex-io commented on May 17, 2024

ReadLine(),有回车符的才能read出数据

from beetlex.

fymeng2017 avatar fymeng2017 commented on May 17, 2024

我试试看 谢谢

from beetlex.

abin30 avatar abin30 commented on May 17, 2024

先关注下

from beetlex.

Grart avatar Grart commented on May 17, 2024

在非HTTP传输环境下,传string可以把长度前置,类似WCF传string 的有一长度编码算法我觉得可以借鉴下
`

static class Program
{
	/// <summary>
	/// 应用程序的主入口点。
	/// </summary>
	[STAThread]
	static void Main()
	{
		int _byteCount = System.Text.Encoding.UTF8.GetByteCount("ABCDEFG");
		var _intEncodeSize = GetEncodedSize(_byteCount);
		var _intEncode = Encode(_byteCount, _intEncodeSize);
		var _dCount = Decode(_intEncode, 0, _intEncode.Length);

	}

	public static byte[] Encode(int byteCount, int size)
	{
		var bytes = new byte[size];
		var offset = 0;
		while ((byteCount & 0xffffff80L) != 0)
		{
			bytes[offset++] = (byte)((byteCount & 0x7f) | 0x80);
			byteCount = byteCount >> 7;
		}
		bytes[offset] = (byte)byteCount;
		return bytes;
	}

	public static int GetEncodedSize(int value)
	{
		int _num = 1;
		while ((value & 0xffffff80L) != 0)
		{
			_num++;
			value = value >> 7;
		}
		return _num;
	}

	public static int Decode(byte[] buffer, int offset, int size)
	{
		int num = 0;
		int value = 0;
		int index = 0;
		bool isValueDecoded = false;
		while (num < size)
		{
			int num2 = buffer[offset];
			value |= (num2 & 0x7f) << (index * 7);
			num++;
			if ((index == 4) && ((num2 & 0xf8) != 0))
			{
				throw new Exception();
			}
			index = (short)(index + 1);
			if ((num2 & 0x80) == 0)
			{
				isValueDecoded = true;
				return value;
			}
			offset++;
		}
		return value;
	}
}`

这个算法会根据字符长度选择最少的byte位数去记录长度。读到长度后再去读后面的string内容

from beetlex.

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.