helios-io / helios

reactive socket middleware for .NET
http://helios-io.github.io/
Apache License 2.0
453 stars 127 forks source link

Wrong tcp packet content ? #57

Closed OlinCamber closed 9 years ago

OlinCamber commented 9 years ago

Hi,

I've discovered your work when I was looking for a framework to manage TCP transport on my application.

Using TimeService example I've created a small program which send data over tcp

Here the code of the startup:

            var host = IPAddress.Parse("192.168.0.72");
            var port = 7000;
            var bootstrapper = new ClientBootstrap().SetTransport(TransportType.Tcp).Build();

            client = bootstrapper.NewConnection(Node.Empty(), NodeBuilder.BuildNode().Host(host).WithPort(port));
            client.OnConnection += (address, connection) =>
            {
                Console.WriteLine("Confirmed connection with host.");
                connection.BeginReceive(ReceivedCallback);
            };
            client.OnDisconnection += (address, reason) => Console.WriteLine("Disconnected.");
            LoopConnect();
            Write();

and here concerning the Write method:

            var command = Encoding.ASCII.GetBytes("TEST");
            _client.Send(command, 0, command.Length, new EmptyNode());

My server receive the message. but with invalid characters at the beginning. I've checked using wireshark the communication and the sent contains invalid chars at the beginning.

Here the Content in hex for my "TEST" message 04:00:00:00:54:45:53:54

How can I fix it ?

Thanks in advance !

Aaronontheweb commented 9 years ago

Hi Olin!

The invalid characters at the beginning are from the https://github.com/helios-io/helios/blob/dev/src/Helios/Serialization/LengthFieldPrepender.cs - this is how we frame messages in Helios by default.

You can turn this off inside ClientBootstrap via the following:

 var bootstrapper = new ClientBootstrap().SetEncoder(new NoOpEncoder()).SetDecoder(new NoOpDecoder()).SetTransport(TransportType.Tcp).Build();

This will not perform any message framing by default, so you need to ensure that somewhere you are using message framing or your application will fail as soon as messages stop being of a fixed / consistent size.

OlinCamber commented 9 years ago

Thanks a lot for the Help! I will test or soon