Giter Club home page Giter Club logo

Comments (19)

vtortola avatar vtortola commented on July 17, 2024

Hi,

Do you have the complete stack trace?

Cheers.

from websocketlistener.

atonamy avatar atonamy commented on July 17, 2024

Yes

 at System.IO.Compression.DeflateStreamNative.CheckResult (Int32 result, System.String where) [0x000b1] in <filename unknown>:0 
  at System.IO.Compression.DeflateStreamNative.ReadZStream (IntPtr buffer, Int32 length) [0x0000e] in <filename unknown>:0 
  at System.IO.Compression.DeflateStream.ReadInternal (System.Byte[] array, Int32 offset, Int32 count) [0x0002f] in <filename unknown>:0 
  at System.IO.Compression.DeflateStream.Read (System.Byte[] dest, Int32 dest_offset, Int32 count) [0x00086] in <filename unknown>:0 
  at vtortola.WebSockets.Deflate.WebSocketDeflateReadStream.Read (System.Byte[] buffer, Int32 offset, Int32 count) [0x00000] in <filename unknown>:0 
  at System.IO.StreamReader.ReadBuffer () [0x0002b] in <filename unknown>:0 
  at System.IO.StreamReader.ReadToEnd () [0x00055] in <filename unknown>:0 
  at vtortola.WebSockets.WebSocketStringExtensions+<ReadStringAsync>d__0.MoveNext () [0x000b3] in <filename unknown>:0 
--- End of stack trace from previous location where exception was thrown ---
  at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x0000c] in <filename unknown>:0 
  at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Threading.Tasks.Task task) [0x0004e] in <filename unknown>:0 
  at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Threading.Tasks.Task task) [0x0002e] in <filename unknown>:0 
  at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd (System.Threading.Tasks.Task task) [0x0000b] in <filename unknown>:0 
  at System.Runtime.CompilerServices.ConfiguredTaskAwaitable`1+ConfiguredTaskAwaiter[TResult].GetResult () [0x00000] in <filename unknown>:0 

from websocketlistener.

vtortola avatar vtortola commented on July 17, 2024

Does it work if you not use the compression?

from websocketlistener.

atonamy avatar atonamy commented on July 17, 2024

Yes, without compression it works. But how to fix issue with compression?

from websocketlistener.

vtortola avatar vtortola commented on July 17, 2024

I have been trying to get time to set up a box with Mono but no luck. Which client are you using?

from websocketlistener.

atonamy avatar atonamy commented on July 17, 2024

I using Ubuntu 14.04.4 LTS and Mono version 4.2.2
with IDE MonoDevelop version 5.10
http://www.mono-project.com/download/

from websocketlistener.

vtortola avatar vtortola commented on July 17, 2024

I mean as websocket client

from websocketlistener.

atonamy avatar atonamy commented on July 17, 2024

latest 2.2.0.1 from nuget https://www.nuget.org/packages/vtortola.WebSocketListener/

from websocketlistener.

vtortola avatar vtortola commented on July 17, 2024

WebSocketListener is the server, I mean the client. Probably you are using a browser like Google Chrome or a client like ClientWebSocket or WebSocket4Net.

from websocketlistener.

atonamy avatar atonamy commented on July 17, 2024

Google chrome latest stable release

from websocketlistener.

atonamy avatar atonamy commented on July 17, 2024

Same issue with Firefox

from websocketlistener.

pboyer avatar pboyer commented on July 17, 2024

I've also run into similar stack traces on recent builds of Mono. @atonamy What happens when you try to do trivial zip operations with System.IO.Compression?

from websocketlistener.

vtortola avatar vtortola commented on July 17, 2024

Can you run this little test and see what happens:

public class DummyWsStream : WebSocketMessageReadStream
{
    MemoryStream _ms;
    public DummyWsStream(MemoryStream ms)
    {
        _ms = ms;
    }

    public override WebSocketExtensionFlags Flags
    {
        get { return new WebSocketExtensionFlags(); }
    }

    public override WebSocketMessageType MessageType
    {
        get { return WebSocketMessageType.Text; }
    }

    public override int Read(byte[] buffer, int offset, int count)
    {
        return _ms.Read(buffer, offset, count);
    }

    public override async Task<int> ReadAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken)
    {
        return _ms.Read(buffer, offset, count);
    }
}

static async Task Test()
{
    await Task.Yield();

    String test = String.Join(", ", Enumerable.Range(0, 50).Select(i => Guid.NewGuid().ToString()));

    var ms = new MemoryStream();
    using (var deflate = new DeflateStream(ms, CompressionMode.Compress, true))
    {
        var encoded = Encoding.UTF8.GetBytes(test);
        deflate.Write(encoded, 0, encoded.Length);
        deflate.Dispose();
        ms.Seek(0, SeekOrigin.Begin);
    }

    var wsdeflate = new WebSocketDeflateReadStream(new DummyWsStream(ms));

    Byte[] buffer = new Byte[128];
    using (var target = new MemoryStream())
    {
        int readed = -1;
        do
        {
            readed = await wsdeflate.ReadAsync(buffer, 0, buffer.Length).ConfigureAwait(false);
            await target.WriteAsync(buffer, 0, readed).ConfigureAwait(false);
        }
        while (readed != 0);

        var test2 = Encoding.UTF8.GetString(target.ToArray());
        Console.WriteLine(test2 == test ? "Test passed" : "Test failed");
    }
}

static void Main(string[] args)
{
    Test().Wait();
}

from websocketlistener.

atonamy avatar atonamy commented on July 17, 2024

@vtortola Which namespace I should include?

Anyway I just ran this code on my Mono machine and result is
"Test passed"

If you want to repeat this error. Just run this sample https://github.com/vtortola/WebSocketListener/tree/master/samples/RxWebSocketChat
(Server and Client - using Chrome in Mono environment)

from websocketlistener.

atonamy avatar atonamy commented on July 17, 2024

@pboyer I tried to execute this code below and it works without any problem. System.IO.Compression works on Mono. Problem with something else.

using System;
using System.IO;
using System.IO.Compression;
using System.Text;

namespace compression
{
    class MainClass
    {
        public static void Main (string[] args)
        {
            var inputString = "“ ... ” test how it works compression";
            byte[] compressed;
            string output;


            using (var outStream = new MemoryStream())
            {
                using (var tinyStream = new GZipStream(outStream, CompressionMode.Compress))
                using (var mStream = new MemoryStream(Encoding.UTF8.GetBytes(inputString)))
                    mStream.CopyTo(tinyStream);

                compressed = outStream.ToArray();
            }

            // “compressed” now contains the compressed string.
            // Also, all the streams are closed and the above is a self-contained operation.

            using (var inStream = new MemoryStream(compressed))
            using (var bigStream = new GZipStream(inStream, CompressionMode.Decompress))
            using (var bigStreamOut = new MemoryStream())
            {
                bigStream.CopyTo(bigStreamOut);
                output = Encoding.UTF8.GetString(bigStreamOut.ToArray());
            }

            // “output” now contains the uncompressed string.
            Console.WriteLine(output);


            using (MemoryStream compressedDataStream = new MemoryStream(new byte[] {}))
            {
                using (GZipStream zip = new GZipStream(compressedDataStream, CompressionMode.Decompress)){
                    byte[] buffer = new byte[8192];
                    int test = zip.Read(buffer, 0, buffer.Length); 
                }
            }

            Console.WriteLine("Test for empty data also works.");
        }

    }

}

from websocketlistener.

jacobs100500 avatar jacobs100500 commented on July 17, 2024

It's a bug of the Mono. When use the function ReadToEnd of the StreamReader, throws an error (ReadInternal). I use Mono version 4.2.3.4, but this bug is not yet fixed. May be in version > 4.3 this problem will be solved.

from websocketlistener.

vtortola avatar vtortola commented on July 17, 2024

pheww... thanks @jacobs100500 for stepping in 👍

@atonamy maybe you can copy the message stream content to a MemoryStream and use Encoding.UTF8.GetString(memoryStream.ToArray()) to see if it works, although it seems like bad idea to create big Byte[] objects, because if you need compression I guess you are using large messages.

from websocketlistener.

atonamy avatar atonamy commented on July 17, 2024

@vtortola how to copy the message stream? Any code example how temporary solve this issue by in a roundabout way for Mono?

from websocketlistener.

vtortola avatar vtortola commented on July 17, 2024

The message stream implements Stream so you can probably do something like .CopyAsync()

from websocketlistener.

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.