Code-Sharp/WampSharp

How to limit the websocket frame size?

konsultaner opened this issue · 16 comments

I tried to send a large message from wampsharp to my router and got a Max frame length of 65536 has been exceeded. Error. Obviously the default frame length of 65536 was not used by my wampsharp instance.

Is there a way to configure that? I could not find anything in the docs.

darkl commented

You just need to send a payload largen then 64kbyte and you will see that it does not use a websocket continuation frame. This is ok if the router accepts larger frame sizes. But the default frame size is 65536 byte.

darkl commented

Okay, this is a new feature I just implemented. Can you please try it out before I release it to NuGet gallery? It's version 21.0.0-develop-31. In order to install it, you need to create a GitHub token with permissions repo and read:packages. See here how to do it. Generate the token value, and then create a NuGet.config file in your project directory with the following content:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <packageSources>
    <clear />
    <add key="github" value="https://nuget.pkg.github.com/Code-Sharp/index.json" />
  </packageSources>
  <packageSourceCredentials>
    <github>
      <add key="Username" value="USER" />
      <add key="ClearTextPassword" value="TOKEN" />
    </github>
  </packageSourceCredentials>
</configuration>

where TOKEN is the token you generated and USER is your username.

Feature usage:

channelFactory.ConnectToRealm("realm1")
              .WebSocketTransport(new Uri("ws://127.0.0.1:8080/ws"))
              .SetMaxFrameSize(64 * 1024)
              .JsonSerialization()
              .Build();

Thanks
Elad

@darkl perfect, I'll give it a try

@darkl I'm not a c# pro. I ran in an issue when trying the latest stable:

tests.ConnectorTest.Connect

System.TypeInitializationException : Der Typeninitialisierer für "WampSharp.V2.Fluent.NewtonsoftJsonChannelFactoryExtensions" hat eine Ausnahme verurs...

System.TypeInitializationException : Der Typeninitialisierer für "WampSharp.V2.Fluent.NewtonsoftJsonChannelFactoryExtensions" hat eine Ausnahme verursacht.
  ----> System.IO.FileLoadException : Die Datei oder Assembly "Newtonsoft.Json, Version=6.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed" oder eine Abhängigkeit davon wurde nicht gefunden. Die gefundene Manifestdefinition der Assembly stimmt nicht mit dem Assemblyverweis überein. (Ausnahme von HRESULT: 0x80131040)
   bei WampSharp.V2.Fluent.NewtonsoftJsonChannelFactoryExtensions.JsonSerialization(ITransportSyntax transportSyntax)
   bei biz.dls.connector.Connector.<Connect>d__23.MoveNext() in C:\Users\burkh\RiderProjects\biz.dls.connector\biz.dls.connector\Connector.cs:Zeile 32.
--- Ende der Stapelüberwachung vom vorhergehenden Ort, an dem die Ausnahme ausgelöst wurde ---
   bei System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   bei System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   bei System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   bei System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd(Task task)
   bei System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
   bei tests.ConnectorTest.<Connect>d__0.MoveNext() in C:\Users\burkh\RiderProjects\biz.dls.connector\tests\Tests.cs:Zeile 23.
--- Ende der Stapelüberwachung vom vorhergehenden Ort, an dem die Ausnahme ausgelöst wurde ---
   bei System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   bei NUnit.Framework.Internal.ExceptionHelper.Rethrow(Exception exception)
   bei NUnit.Framework.Internal.AsyncInvocationRegion.AsyncTaskInvocationRegion.WaitForPendingOperationsToComplete(Object invocationResult)
   bei NUnit.Framework.Internal.Commands.TestMethodCommand.RunAsyncTestMethod(TestExecutionContext context)
--FileLoadException
   bei WampSharp.V2.Fluent.NewtonsoftJsonChannelFactoryExtensions..cctor()

for some reason the Newtonsoft.Json is 10.0.1 in nuget but at runtime its 6.x.x for some reason? Do you know how to fix this?

@darkl I created a complete new solution and project and just copied all me code. Still getting this error:

is there anything wrong with my packages?

<?xml version="1.0" encoding="utf-8"?>
<packages>
  <package id="Newtonsoft.Json" version="10.0.1" targetFramework="net461" />
  <package id="Fleck" version="1.1.0" targetFramework="net461" />
  <package id="Microsoft.Bcl.AsyncInterfaces" version="1.0.0" targetFramework="net461" />
  <package id="Microsoft.CSharp" version="4.5.0" targetFramework="net461" />
  <package id="Microsoft.IO.RecyclableMemoryStream" version="1.2.2" targetFramework="net461" />
  <package id="NewtonsoftMessagePack" version="0.1.11" targetFramework="net461" />
  <package id="System.Collections.Immutable" version="1.5.0" targetFramework="net461" />
  <package id="System.Reactive" version="4.1.6" targetFramework="net461" />
  <package id="System.Reflection.DispatchProxy" version="4.5.1" targetFramework="net461" />
  <package id="System.Runtime.CompilerServices.Unsafe" version="4.5.2" targetFramework="net461" />
  <package id="System.Threading.Tasks.Dataflow" version="4.9.0" targetFramework="net461" />
  <package id="System.Threading.Tasks.Extensions" version="4.5.3" targetFramework="net461" />
  <package id="System.ValueTuple" version="4.5.0" targetFramework="net461" />
  <package id="WampSharp" version="20.1.1" targetFramework="net461" />
  <package id="WampSharp.Default" version="20.1.1" targetFramework="net461" />
  <package id="WampSharp.Default.Client" version="20.1.1" targetFramework="net461" />
  <package id="WampSharp.Default.Router" version="20.1.1" targetFramework="net461" />
  <package id="WampSharp.Fleck" version="20.1.1" targetFramework="net461" />
  <package id="WampSharp.NewtonsoftJson" version="20.1.1" targetFramework="net461" />
  <package id="WampSharp.NewtonsoftMessagePack" version="20.1.1" targetFramework="net461" />
  <package id="WampSharp.RawSocket" version="20.1.1" targetFramework="net461" />
  <package id="WampSharp.WebSockets" version="20.1.1" targetFramework="net461" />
  <package id="log4net" version="2.0.12" targetFramework="net461" />
</packages>
darkl commented

@darkl Still getting the error with Newtonsoft.Json trying to link the v10 to v6. I have no Idea why...

is this the issue?

image

@darkl I found the issue. I needed to create the project as netstandard2.1 because the megpack package does not support net461

<TargetFrameworks>netstandard2.0;netstandard2.1</TargetFrameworks>

There is a dependancy missing. Thats why its impossible to get it to work under net461.

@darkl When adding SetMaxFrameSize(64 * 1024) the connection is not getting established anymore.

darkl commented

I think I fixed it, try 21.0.0-develop-34.

Regarding the Newtonsoft.Json dependency, I'll have to try figuring it out later.

Elad

@darkl works like charm. Thx for getting it done. Are you going to release it soon or should I stick with the develop-34 version?

darkl commented

Stick for now with develop-34. I do plan to release a new version to NuGet, but it will be some time in the next two months.

darkl commented

Version 22.5.1 is now available on NuGet!

awesome! thank you