Comments (19)
Hi,
Do you have the complete stack trace?
Cheers.
from websocketlistener.
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.
Does it work if you not use the compression?
from websocketlistener.
Yes, without compression it works. But how to fix issue with compression?
from websocketlistener.
I have been trying to get time to set up a box with Mono but no luck. Which client are you using?
from websocketlistener.
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.
I mean as websocket client
from websocketlistener.
latest 2.2.0.1 from nuget https://www.nuget.org/packages/vtortola.WebSocketListener/
from websocketlistener.
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.
Google chrome latest stable release
from websocketlistener.
Same issue with Firefox
from websocketlistener.
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.
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.
@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.
@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.
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.
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.
@vtortola how to copy the message stream? Any code example how temporary solve this issue by in a roundabout way for Mono?
from websocketlistener.
The message stream implements Stream
so you can probably do something like .CopyAsync()
from websocketlistener.
Related Issues (20)
- I am trying to upgrade from V2.2.0.1 to V3.0.0 but it errors out. HOT 5
- Does WebSocketListener work with the HoloLens (UWP)? HOT 1
- V3.0.0 does not work with Mono v4.6.2 HOT 3
- How to bypass CORS? HOT 1
- IOException Issues Randomly HOT 1
- IE Origin HOT 2
- WSS Configuration HOT 2
- On quick client disconnect, ObjectDisposedException being thrown HOT 1
- WebSocketMessageReadNetworkStream can only start with a Text or Binary frame, not Continuation HOT 2
- WebSocketHandshaker.ParseWebSocketProtocol throws a NullReferenceException HOT 1
- Server does not detect broken link on linux
- TLS 1.2 is not supported HOT 1
- Cannot understand frame header exception when receiving messages from Javascript HOT 5
- SSL Deserialize Message not working HOT 4
- How to use OnHttpNegotiation in 3.0.0
- Is there a sample including Authentication? HOT 1
- Some Information about Client HOT 1
- Try to Secure WebSocket: Unknow error while processing the certificate
- Is WebSocketListener good enough out of the box for video streaming? HOT 2
- Websocket Listener is able to accept incoming data from Client but Websocket Listener thinks connection with client is closed. HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from websocketlistener.