Coder Social home page Coder Social logo

pusher-websocket-dotnet's People

Contributors

agatav avatar benjamin-tang-pusher avatar benw-pusher avatar boogier avatar ccaseypusher avatar cdauphinee avatar damdo avatar danielrbrowne avatar erwin42 avatar imaji avatar jameshfisher avatar kn100 avatar leggetter avatar mchandschuh avatar meenaalfons avatar pusher-ci avatar singhashmeet avatar willsewell avatar zimbatm avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

pusher-websocket-dotnet's Issues

Xamarin support

Hi There,

I'm trying to use this nuget package in Xamarin to integrate Pusher with an Android app I'm working on but I'm not getting much love.

It looks like PusherClient is missing the 'MonoAndroid,Version=v7.0' target. The two dependencies, Websocket4Net and NewtonJson can be installed without any issue.

I'm not sure what is involved to add that. I've never worked on a NuGet package before. Is this something you can change quickly or maybe I can create a Pull Request if I'm pointed in the correct direction

Output from trying to install below:

Attempting to gather dependency information for package 'PusherClient.0.4.0' with respect to project 'Playground.Droid', targeting 'MonoAndroid,Version=v7.0'
Attempting to resolve dependencies for package 'PusherClient.0.4.0' with DependencyBehavior 'Lowest'
Resolving actions to install package 'PusherClient.0.4.0'
Resolved actions to install package 'PusherClient.0.4.0'
For adding package 'PusherClient.0.4.0' to project 'Playground.Droid' that targets 'monoandroid70'.
Install failed. Rolling back...
Package 'PusherClient.0.4.0 : Newtonsoft.Json [9.0.1, ), WebSocket4Net [0.14.1, )' does not exist in project 'Playground.Droid'
Package 'PusherClient.0.4.0 : Newtonsoft.Json [9.0.1, ), WebSocket4Net [0.14.1, )' does not exist in folder '/Users/brooney/projects/xamarin/Playground/packages'
Could not install package 'PusherClient 0.4.0'. You are trying to install this package into a project that targets 'MonoAndroid,Version=v7.0', but the package does not contain any assembly references or content files that are compatible with that framework. For more information, contact the package author.

403 Forbidden should be handled when authenticating user

According to the docs, the server should handle a rejected authentication by sending a 403 Forbidden status. In practice, this causes an NRE. We are working around this by ensuring we send back a body with the key auth like { auth: 'invalid'} but it would be great if the library could just recognize an error occurred from the status code.

`/p:OutputPath=.\ ` in `package.cmd` makes all binaries same!

/p:OutputPath=.\ in package.cmd makes net45, net46 and netstandard1.6 binaries same.

"%ProgramFiles(x86)%\Microsoft Visual Studio\2017\Enterprise\MSBuild\15.0\Bin\amd64\msbuild.exe" PusherClient/PusherClient.csproj /t:pack /p:configuratio=release /p:OutputPath=.\

Please check same 98df0b35 CRC-32 values printed from unzip.

USER@DD36 ~
$ unzip -v /cygdrive/d/DL/pusherclient.1.0.2.nupkg
Archive:  /cygdrive/d/DL/pusherclient.1.0.2.nupkg
 Length   Method    Size  Cmpr    Date    Time   CRC-32   Name
--------  ------  ------- ---- ---------- ----- --------  ----
     506  Defl:N      273  46% 06-18-2019 10:53 88afae54  _rels/.rels
    2157  Defl:N      605  72% 06-18-2019 10:53 bb628f90  PusherClient.nuspec
   40960  Defl:N    17118  58% 06-18-2019 09:53 98df0b35  lib/net45/PusherClient.dll
   40960  Defl:N    17118  58% 06-18-2019 09:53 98df0b35  lib/net46/PusherClient.dll
   40960  Defl:N    17118  58% 06-18-2019 09:53 98df0b35  lib/netstandard1.6/PusherClient.dll
     465  Defl:N      207  56% 06-18-2019 10:53 bc4d7cde  [Content_Types].xml
     774  Defl:N      453  42% 06-18-2019 10:53 d0e43126  package/services/metadata/core-properties/ffa56fe658a247c99ecc8fa97973a1d6.psmdcp
    9468  Stored     9468   0% 06-18-2019 03:04 2c04e5e3  .signature.p7s
--------          -------  ---                            -------
  136250            62360  54%                            8 files
Verified by `sha512` hash output. I have extracted PusherClient.dll files from [pusherclient.1.0.2.nupkg](https://www.nuget.org/api/v2/package/PusherClient/1.0.2)
USER@DD36 ~
$ sha512sum.exe `find /cygdrive/c/Users/USER/Desktop/lib -name PusherClient.dll`
181a209cec5aefddd5495c2d2d6dbfa65d056ba4a084be26d14ba77ef7679b66bbca8b5a79a044d0067f18b876821a64508775eff1d93faef4125d592f08dd4b */cygdrive/c/Users/USER/Desktop/lib/net45/PusherClient.dll
181a209cec5aefddd5495c2d2d6dbfa65d056ba4a084be26d14ba77ef7679b66bbca8b5a79a044d0067f18b876821a64508775eff1d93faef4125d592f08dd4b */cygdrive/c/Users/USER/Desktop/lib/net46/PusherClient.dll
181a209cec5aefddd5495c2d2d6dbfa65d056ba4a084be26d14ba77ef7679b66bbca8b5a79a044d0067f18b876821a64508775eff1d93faef4125d592f08dd4b */cygdrive/c/Users/USER/Desktop/lib/netstandard1.6/PusherClient.dll

So please exclude /p:OutputPath=.\ from package.cmd:

"%ProgramFiles(x86)%\Microsoft Visual Studio\2017\Professional\MSBuild\15.0\Bin\amd64\msbuild.exe" PusherClient/PusherClient.csproj /t:pack /p:Configuration=Release

Although this will produce nupkg in Release folder, all binaries are separatedly built and composed.

USER@DD36 ~
$ sha512sum.exe `find /cygdrive/c/Users/USER/Desktop/lib -name PusherClient.dll`
69b0b6a08503d2c11750660469323effe9ceb9b80062c6095504dc5fcc7d808f6d3ed805fd20848ae7dac7b2de082475056db59b43a6de2075e628cb91b65d4c */cygdrive/c/Users/USER/Desktop/lib/net45/PusherClient.dll
dee2555bd9d74ca24fcfc49e291694417615cb0c4758fa777caf04091f39152f4d45376cdf1b67d227a42bbef63bbfd532d909c6237a1418bee78f120d770afe */cygdrive/c/Users/USER/Desktop/lib/net46/PusherClient.dll
9d5cc830920ef8ca8579e825e1acf84ff8ecc670b69bf4500940250065a30da0a8199350d6069ea3ffa12b29cf66145cb3c66350d428b7fffb57ae1f56063376 */cygdrive/c/Users/USER/Desktop/lib/netstandard1.6/PusherClient.dll

It works, just once.

Hi,

I've been trying to port this library for Xamarin and to be honest it's pretty easy since WebSocket4Net also Supports Xamarin. Only thing I had to do was remove the Settings since Xamarin doesn't have System.Configuration.

So, I subscribed to a private channel with the following code:

      var _chatChannel = pusher.Subscribe ("channelname");
        _chatChannel.Subscribed += _chatChannel_Subscribed;
        _chatChannel.Bind("NEW_MESSAGE", (data) =>
            {
                Console.WriteLine("[" + data.name + "] " + data.message);
            });

It seems to work.. the event fires when I send a message with event name NEW_MESSAGE. But as soon as I send another one it doesn't come into the Bind anymore so the event is not caught..

Any ideas what this might be?

System.InvalidOperationException (Connection.websocket_Opened)

I am using C# PusherClient 1.1.1 (Nuget) in a Xamarin mobile application and I am getting multiple crashes during testing in this library. It seems as there is some error handling missing and that the lib is sensitive to the communication challanges of mobile networks. Here is the stack trace:

TaskCompletionSource`1[TResult].SetResult (TResult result)
Connection.websocket_Opened (System.Object sender, System.EventArgs e)
WebSocket.OnHandshaked ()
Handshake.ExecuteCommand (WebSocket4Net.WebSocket session, WebSocket4Net.WebSocketCommandInfo commandInfo)
WebSocket.ExecuteCommand (WebSocket4Net.WebSocketCommandInfo commandInfo)
WebSocket.OnDataReceived (System.Byte[] data, System.Int32 offset, System.Int32 length)
WebSocket.client_DataReceived (System.Object sender, SuperSocket.ClientEngine.DataEventArgs e)
ClientSession.OnDataReceived (System.Byte[] data, System.Int32 offset, System.Int32 length)
AuthenticatedStreamTcpSession+d__12.MoveNext ()
AsyncMethodBuilderCore+<>c.b__6_1 (System.Object state)
QueueUserWorkItemCallback.WaitCallback_Context (System.Object state)
ExecutionContext.RunInternal (System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, System.Object state, System.Boolean preserveSyncCtx)
ExecutionContext.Run (System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, System.Object state, System.Boolean preserveSyncCtx)
IThreadPoolWorkItem.ExecuteWorkItem ()
ThreadPoolWorkQueue.Dispatch ()
_ThreadPoolWaitCallback.PerformWaitCallback ()

System.AggregateException has been thrown while trying to connect to a private channel

Hello! I have this exception while trying to connect to a private channel. I am using PusherClient 1.1.0 on Xamarin.Forms and I am testing with an iPhone simulator and a real device.

_pusherClient = new Pusher(ApplicationSettings.PusherId, new PusherOptions
{
    Authorizer = new HttpAuthorizer("our url"),
});

_pusherClient.ConnectionStateChanged += PusherConnectionChanged;
_pusherClient.Error += PusherError;

// _subscription = our private channel
var channel = await _pusherClient.SubscribeAsync(_subscription);
channel.Subscribed += ChannelSubscribed;

channel.Bind("userUpdated", (dynamic data) =>
{
    Console.WriteLine(data);
});

await _pusherClient.ConnectAsync();

This is the exception:
Screen Shot 2019-11-13 at 10 14 44

This is the inner exception:

{Newtonsoft.Json.JsonReaderException: Unexpected character encountered while parsing value: S. Path '', line 0, position 0.
  at Newtonsoft.Json.JsonTextReader.ParseValue () [0x002b3] in <12891e825fce44a581e5bbbb579c1d49>:0 
  at Newtonsoft.Json.JsonTextReader.Read () [0x0004c] in <12891e825fce44a581e5bbbb579c1d49>:0 
  at Newtonsoft.Json.JsonReader.ReadAndMoveToContent () [0x00000] in <12891e825fce44a581e5bbbb579c1d49>:0 
  at Newtonsoft.Json.JsonReader.ReadForType (Newtonsoft.Json.Serialization.JsonContract contract, System.Boolean hasConverter) [0x0004a] in <12891e825fce44a581e5bbbb579c1d49>:0 
  at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.Deserialize (Newtonsoft.Json.JsonReader reader, System.Type objectType, System.Boolean checkAdditionalContent) [0x000db] in <12891e825fce44a581e5bbbb579c1d49>:0 
  at Newtonsoft.Json.JsonSerializer.DeserializeInternal (Newtonsoft.Json.JsonReader reader, System.Type objectType) [0x00054] in <12891e825fce44a581e5bbbb579c1d49>:0 
  at Newtonsoft.Json.JsonSerializer.Deserialize (Newtonsoft.Json.JsonReader reader, System.Type objectType) [0x00000] in <12891e825fce44a581e5bbbb579c1d49>:0 
  at Newtonsoft.Json.JsonConvert.DeserializeObject (System.String value, System.Type type, Newtonsoft.Json.JsonSerializerSettings settings) [0x0002d] in <12891e825fce44a581e5bbbb579c1d49>:0 
  at Newtonsoft.Json.JsonConvert.DeserializeObject[T] (System.String value, Newtonsoft.Json.JsonSerializerSettings settings) [0x00000] in <12891e825fce44a581e5bbbb579c1d49>:0 
  at Newtonsoft.Json.JsonConvert.DeserializeObject[T] (System.String value) [0x00000] in <12891e825fce44a581e5bbbb579c1d49>:0 
  at Newtonsoft.Json.JsonConvert.DeserializeAnonymousType[T] (System.String value, T anonymousTypeObject) [0x00000] in <12891e825fce44a581e5bbbb579c1d49>:0 
  at PusherClient.Pusher.SubscribeToChannel (System.String channelName) [0x0008e] in <3948be5ee8fa4f22bfbd47bfe37b2beb>:0 }

If I connect to a public channel everything works correctly, do you guys have any ideas?

Pong reply not received

I'm running pusher in a long running process on mono. The PusherClient.Pusher instance is created early in the process's life cycle. The process then spends time waiting for work to do, and upon receiving work, it will connect to a presence channel. This intermittently works, but sometimes I get the following error thrown:

Unhandled Exception:
PusherClient.PusherException: Pong reply not received
at PusherClient.Connection.ParseError (System.String data) [0x00000] in :0
at PusherClient.Connection.websocket_MessageReceived (System.Object sender, WebSocket4Net.MessageReceivedEventArgs e) [0x00000] in :0
at WebSocket4Net.WebSocket.FireMessageReceived (System.String message) [0x00000] in :0
at WebSocket4Net.Command.Text.ExecuteCommand (WebSocket4Net.WebSocket session, WebSocket4Net.WebSocketCommandInfo commandInfo) [0x00000] in :0
at WebSocket4Net.WebSocket.ExecuteCommand (WebSocket4Net.WebSocketCommandInfo commandInfo) [0x00000] in :0
at WebSocket4Net.WebSocket.OnDataReceived (System.Byte[] data, Int32 offset, Int32 length) [0x00000] in :0
at WebSocket4Net.WebSocket.client_DataReceived (System.Object sender, SuperSocket.ClientEngine.DataEventArgs e) [0x00000] in :0
at SuperSocket.ClientEngine.ClientSession.OnDataReceived (System.Byte[] data, Int32 offset, Int32 length) [0x00000] in :0
at SuperSocket.ClientEngine.AsyncTcpSession.ProcessReceive (System.Net.Sockets.SocketAsyncEventArgs e) [0x00000] in :0
at SuperSocket.ClientEngine.AsyncTcpSession.SocketEventArgsCompleted (System.Object sender, System.Net.Sockets.SocketAsyncEventArgs e) [0x00000] in :0
at System.Net.Sockets.SocketAsyncEventArgs.OnCompleted (System.Net.Sockets.SocketAsyncEventArgs e) [0x00000] in :0
at System.Net.Sockets.SocketAsyncEventArgs.ReceiveCallback (IAsyncResult ares) [0x00000] in :0
at System.Net.Sockets.SocketAsyncEventArgs.DispatcherCB (IAsyncResult ares) [0x00000] in :0

Following this the process exits due to the unhandled exception. Any thoughts/recommendations?

PresenceChannel - An item with the same key has already been added

Hi

I'm using PusheClient and i like it.
Sometimes i get exception

System.ArgumentException: An item with the same key has already been added.
at System.ThrowHelper.ThrowArgumentException(ExceptionResource resource)
at System.Collections.Generic.Dictionary2.Insert(TKey key, TValue value, Boolean add) at CallSite.Target(Closure , CallSite , Dictionary2 , String , Object )
at PusherClient.PresenceChannel.AddMember(String data)
at PusherClient.Connection.websocket_MessageReceived(Object sender, MessageReceivedEventArgs e)
at WebSocket4Net.WebSocket.FireMessageReceived(String message)
at WebSocket4Net.Command.Text.ExecuteCommand(WebSocket session, WebSocketCommandInfo commandInfo)
at WebSocket4Net.WebSocket.ExecuteCommand(WebSocketCommandInfo commandInfo)
at WebSocket4Net.WebSocket.OnDataReceived(Byte[] data, Int32 offset, Int32 length)
at WebSocket4Net.WebSocket.client_DataReceived(Object sender, DataEventArgs e)
at SuperSocket.ClientEngine.ClientSession.OnDataReceived(Byte[] data, Int32 offset, Int32 length)
at SuperSocket.ClientEngine.AsyncTcpSession.ProcessReceive(SocketAsyncEventArgs e)
at SuperSocket.ClientEngine.AsyncTcpSession.SocketEventArgsCompleted(Object sender, SocketAsyncEventArgs e)
at System.Net.Sockets.SocketAsyncEventArgs.OnCompleted(SocketAsyncEventArgs e)
at System.Net.Sockets.SocketAsyncEventArgs.ExecutionCallback(Object ignored)
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Net.Sockets.SocketAsyncEventArgs.FinishOperationSuccess(SocketError socketError, Int32 bytesTransferred, SocketFlags flags)
at System.Net.Sockets.SocketAsyncEventArgs.CompletionPortCallback(UInt32 errorCode, UInt32 numBytes, NativeOverlapped* nativeOverlapped)
at System.Threading._IOCompletionCallback.PerformIOCompletionCallback(UInt32 errorCode, UInt32 numBytes, NativeOverlapped* pOVERLAP)

And my app is crushed with domain unhandled exception.
PusherClient try to add one key in dictionary at the same time.
I don't know whether is correct to send two ore more presence event at one time, but it possible to use concurrent dictionary to solve this issue.

I have attached pull request

The application hangs if connection fails.

I created a simple console application that subscribes to a channel. When I disable the connection to simulate a connection failure Pusher Client tries desperately to reconnect and after some seconds he hangs.

Hangs with "conecting" status. That is the log:

Connection state: Disconnected
Connection state: Connecting
Pusher Error: 0 : Error: System.Net.Sockets.SocketException (0x80004005): The requested name is valid, but no data of the requested type was found
Pusher Warning: 0 : Websocket connection has been closed
Connection state: Disconnected
Connection state: Connecting
Pusher Error: 0 : Error: System.Net.Sockets.SocketException (0x80004005): The requested name is valid, but no data of the requested type was found
Pusher Warning: 0 : Websocket connection has been closed
Connection state: Disconnected
Connection state: Connecting

ProcessExplorer shows the resource consuming.
image

System.NullReferenceException at PusherClient.Pusher.SubscribeToChannel(ChannelTypes type, String channelName)

Exception type: System.NullReferenceException
Message: Object reference not set to an instance of an object.
Stacktrace:
at PusherClient.Pusher.SubscribeToChannel(ChannelTypes type, String channelName)
at PusherClient.Pusher.Subscribe(String channelName)
at PusherClient.Pusher.SubscribeExistingChannels()
at PusherClient.Pusher._connection_ConnectionStateChanged(Object sender, ConnectionState state)
at PusherClient.Connection.ChangeState(ConnectionState state)
at PusherClient.Connection.ParseConnectionEstablished(String data)
at PusherClient.Connection.websocket_MessageReceived(Object sender, MessageReceivedEventArgs e)
at WebSocket4Net.WebSocket.FireMessageReceived(String message)
at WebSocket4Net.Command.Text.ExecuteCommand(WebSocket session, WebSocketCommandInfo commandInfo)
at WebSocket4Net.WebSocket.ExecuteCommand(WebSocketCommandInfo commandInfo)
at WebSocket4Net.WebSocket.OnDataReceived(Byte[] data, Int32 offset, Int32 length)
at WebSocket4Net.WebSocket.client_DataReceived(Object sender, DataEventArgs e)
at SuperSocket.ClientEngine.ClientSession.OnDataReceived(Byte[] data, Int32 offset, Int32 length)
at SuperSocket.ClientEngine.SslStreamTcpSession.OnDataRead(IAsyncResult result)
at System.Net.LazyAsyncResult.Complete(IntPtr userToken)
at System.Net.LazyAsyncResult.ProtectedInvokeCallback(Object result, IntPtr userToken)
at System.Net.Security._SslStream.ProcessFrameBody(Int32 readBytes, Byte[] buffer, Int32 offset, Int32 count, AsyncProtocolRequest asyncRequest)
at System.Net.Security._SslStream.ReadFrameCallback(AsyncProtocolRequest asyncRequest)
at System.Net.AsyncProtocolRequest.CompleteRequest(Int32 result)
at System.Net.FixedSizeReader.CheckCompletionBeforeNextRead(Int32 bytes)
at System.Net.FixedSizeReader.ReadCallback(IAsyncResult transportResult)
at System.Net.LazyAsyncResult.Complete(IntPtr userToken)
at System.Net.ContextAwareResult.CompleteCallback(Object state)
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Net.ContextAwareResult.Complete(IntPtr userToken)
at System.Net.LazyAsyncResult.ProtectedInvokeCallback(Object result, IntPtr userToken)
at System.Net.Sockets.BaseOverlappedAsyncResult.CompletionPortCallback(UInt32 errorCode, UInt32 numBytes, NativeOverlapped* nativeOverlapped)
at System.Threading._IOCompletionCallback.PerformIOCompletionCallback(UInt32 errorCode, UInt32 numBytes, NativeOverlapped* pOVERLAP)

Pusher connetion stuck on connecting

My pusher connection repeating on connecting -> disconnected -> waiting to reconnecting, I am sure the cluster and app key is correct.

There is no error throw to error event and trace is empty also.

I checked debug console in pusher
image

it is repeating connection and disconnection

Prebuilded dll

Hello,

I am on VS2010 Express. So Nuget and manual build is not working out of the box.

Is it possible download builded dll some where?
Could you please share it?

Incompatibility with il2cpp due to dynamic keyword

I have a Unity 2019.2 project that builds for iOS, using the il2cpp scripting back-end. At run time, I receive the following exception whenever a dynamic is read or written to (i.e. receiving messages or subscribing to a presence channel):

[Exception] NullReferenceException: Object reference not set to an instance of an object.
    System.Linq.Expressions.Interpreter.LightLambda.MakeRunDelegateCtor (System.Type delegateType) (at <00000000000000000000000000000000>:0)
    System.Linq.Expressions.Interpreter.LightLambda.GetRunDelegateCtor (System.Type delegateType) (at <00000000000000000000000000000000>:0)
    System.Linq.Expressions.Interpreter.LightLambda.MakeDelegate (System.Type delegateType) (at <00000000000000000000000000000000>:0)
    System.Linq.Expressions.Expression`1[TDelegate].Compile (System.Boolean preferInterpretation) (at <00000000000000000000000000000000>:0)
    System.Runtime.CompilerServices.CallSite`1[T].MakeUpdateDelegate () (at <00000000000000000000000000000000>:0)
    System.Runtime.CompilerServices.CallSite`1[T].GetUpdateDelegate (T& addr) (at <00000000000000000000000000000000>:0)
    System.Runtime.CompilerServices.CallSite`1[T]..ctor (System.Runtime.CompilerServices.CallSiteBinder binder) (at <00000000000000000000000000000000>:0)
    System.Runtime.CompilerServices.CallSite`1[T].Create (System.Runtime.CompilerServices.CallSiteBinder binder) (at <00000000000000000000000000000000>:0)

It seems like it's trying to do run-time code generation. To my knowledge, this isn't supported by il2cpp (and not allowed on iOS, even if it were supported). I suspect the same problem is also present on Android builds.

Looking at the code, I came up with two quick solutions that would fix this:

  1. Replace internal deserialization to dynamic (i.e. used for presence channels) with classes.
  2. Replace the usage of dynamic in the EventEmitter callbacks with string.
    • Interface compatibility can be maintained by having both Action<string> and Action<dynamic> overloads, though internally only Action<string> is stored
    • This also allows the consumer to decide which JSON library to use for message deserialization, and could be useful if they have custom converters.

I have no problem making these changes myself, but I want to put this out there for discussion before opening a PR.

Binding an event listener may race with an event being emitted

The EventEmitter listener collections may be modified by a call to bind or unbind while one of the web socket threads is enumerating the collections in EmitEvent.

While it's very hard to reproduce the necessary timing, this race manifests as an infinite loop in .NET Core.

presence channel member added, how to know easily which member is new?

The librairy offers a list of all current member. However I need to know which one joined it. Subscribed to Added Member function, I can't find an item which returns me this value? I only have access to all present members:

static void _presenceChannel_MemberAdded(object sender)
{
    foreach (var mem in _presenceChannel.Members)

So I figured I could bind on the event when one member joined, but it is not triggered (I believe this is because your librairy intercepts this event already?)

_presenceChannel.Bind("pusher_internal:member_added", (dynamic mem) =>
{

So far, unless there is a simple way I will need to always have a copy of the array of present members, and always compare it to the new members list on _presenceChannel_MemberAdded

However it seems like to much for what it does. Is there a way already to access it? If not I think it would be a nice adding. For now I'm using the last method mentionned.

Thanks

Client should not automatically reconnect after certain errors

If I call ConnectAsync with an invalid application key, the connection will constantly try to reconnect with the invalid key until I call DisconnectAsync. This is easily seen by adding a while (true); to the end of the 'invalid key' acceptance test and watching the trace output.

As a work around, I can call DisconnectAsync in response to the error event being raised, but these two issues cause some worry:
#71
#73

Catching and ignore the NRE in the first issue is fine, but if I ignore the NRE from the second issue, the thread in websocket_Closed will restart the connect loop and I'll end up with a socket leak. I can't tell where the NRE came from.

Ideally, I think the library should be responsible for stopping the reconnects on errors that indicate permanent failure.

Channels lose the subscription when reconnects

My code is similar to the example in this repository:

pusher = new Pusher("key");
pusher.Connected += pusher_Connected;
pusher.ConnectionStateChanged += _pusher_ConnectionStateChanged;
pusher.Connect();
static void pusher_Connected(object sender)
{
    Console.WriteLine("Subscribing to chat");
    chatChannel = pusher.Subscribe("chat");
    chatChannel.Subscribed += _chatChannel_Subscribed;
}
static void _chatChannel_Subscribed(object sender)
{
    Console.WriteLine("Subscribed");
    Console.WriteLine("Hi! Type 'quit' to exit, otherwise type anything to chat!");

    chatChannel.Bind("my-message", (dynamic data) =>
    {
        Console.WriteLine("[" + data.name + "] " + data.message);
    });
}

When the connection fails and PusherClient reconnects, all subscriptions are lost.
In this particular case, this happens because of this code on Subscribe method:

if (Channels.ContainsKey(channelName)){
    Trace.TraceEvent(TraceEventType.Warning, 0, "Channel '" + channelName + "' is already subscribed to. Subscription event has been ignored.");
    return Channels[channelName];
}

Log:

Connection state: Connecting
Pusher Information: 0 : Websocket opened OK.
Pusher Information: 0 : Websocket message received: {"data":"{\"activity_timeout\":120,\"socket_id\":\"2096928683.2093493135\"}","event":"pusher:conne
ction_established"}
Connection state: Connected
Subscribing to chat
Pusher Information: 0 : Sending: {"event":"pusher:subscribe","data":{"channel":"chat"}}
Pusher Information: 0 : Websocket message received: {"channel":"chat","data":{},"event":"pusher_internal:subscription_succeeded"}
Subscribed
Hi! Type 'quit' to exit, otherwise type anything to chat!
# connection failure
Connection state: Disconnected
Connection state: Connecting
Pusher Information: 0 : Websocket opened OK.
Pusher Information: 0 : Websocket message received: {"data":"{\"activity_timeout\":120,\"socket_id\":\"2470478451.2274211923\"}","event":"pusher:conne
ction_established"}
Connection state: Connected
Subscribing to chat
Pusher Warning: 0 : Channel 'chat' is already subscribed to. Subscription event has been ignored.

I can think in two solutions for this.

  1. Add a Channels.Clear(); on the Connected event and let the responsibility to re-subscribe for those who are using the library. This will solve the problem for this code I posted, but, I'm not sure this is the right choice.
  2. Make pusher explicit re-send all channel subscriptions and update the channels. I'm not sure how to implement this.

Support for netcoreapp

The dependencies Websocket4Net and Json.Net supports the profile .NETCoreApp,Version=v1.1, can this be supported as well

How to load this package into Unity?

I have some issues adding this package into Unity. My method was to install it using Visual Studio and moving the .dll file to the Assets/Plugins folder of Unity. I'm not sure if this is the right way because it throws several errors.

Please help.

Connection to multiple channes doesn't seem working

I use Pusher for connecting to BitStamp exchange ( https://www.bitstamp.net/websocket/ ) to get orderbooks, and it works for a single currency. If I try to connect to several channels only orderbooks from last connection arrive.

When I try to create multiple Pusher instances, it fails with the error:

Unhandled Exception: System.InvalidOperationException: Collection was modified; enumeration operation may not execute.
   at System.ThrowHelper.ThrowInvalidOperationException_InvalidOperation_EnumFailedVersion()
   at System.Collections.Generic.List`1.Enumerator.MoveNextRare()
   at PusherClient.EventEmitter.EmitEvent(String eventName, String data)
   at PusherClient.Connection.websocket_MessageReceived(Object sender, MessageReceivedEventArgs e)
   at WebSocket4Net.WebSocket.OnDataReceived(Byte[] data, Int32 offset, Int32 length)
   at SuperSocket.ClientEngine.AsyncTcpSession.ProcessReceive(SocketAsyncEventArgs e)
   at System.Net.Sockets.SocketAsyncEventArgs.OnCompleted(SocketAsyncEventArgs e)
   at System.Net.Sockets.SocketAsyncEventArgs.ExecutionCallback(Object state)
   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
   at System.Net.Sockets.SocketAsyncEventArgs.FinishOperationAsyncSuccess(Int32 bytesTransferred, SocketFlags flags)
   at System.NetSystem.InvalidOperationException: Collection was modified; enumeration operation may not execute.
   at System.ThrowHelper.ThrowInvalidOperationException_InvalidOperation_EnumFailedVersion()
   at System.Collections.Generic.List`1.Enumerator.MoveNextRare()
   at PusherClient.EventEmitter.EmitEvent(String eventName, String data)
   at PusherClient.Connection.websocket_MessageReceived(Object sender, MessageReceivedEventArgs e)
   at WebSocket4Net.WebSocket.OnDataReceived(Byte[] data, Int32 offset, Int32 length)
   at SuperSocket.ClientEngine.AsyncTcpSession.ProcessReceive(SocketAsyncEventArgs e)
   at System.Net.Sockets.SocketAsyncEventArgs.OnCompleted(SocketAsyncEventArgs e)
   at System.Net.Sockets.SocketAsyncEventArgs.ExecutionCallback(Object state)
   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
   at System.Net.Sockets.SocketAsyncEventArgs.FinishOperationAsyncSuccess(Int32 bytesTransferred, SocketFlags flags)
   at System.Net.Sockets.SocketAsyncEventArgs.CompletionCallback(Int32 bytesTransferred, SocketFlags flags, SocketError socketError)
   at System.Net.Sockets.SocketAsyncEventArgs.TransferCompletionCallbackCore(Int32 bytesTransferred, Byte[] socketAddress, Int32 socketAddressSize, SocketFlags receivedFlags, SocketError socketError)
   at System.Net.Sockets.SocketAsyncContext.ReceiveOperation.InvokeCallback()
   at System.Net.Sockets.SocketAsyncContext.AsyncOperation.<>c.<TryCompleteOrAbortAsync>b__14_0(Object o)
   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
   at System.Threading.ThreadPoolWorkQueue.Dispatch()
.Sockets.SocketAsyncEventArgs.CompletionCallback(Int32 bytesTransferred, SocketFlags flags, SocketError socketError)
   at System.Net.Sockets.SocketAsyncEventArgs.TransferCompletionCallbackCore(Int32 bytesTransferred, Byte[] socketAddress, Int32 socketAddressSize, SocketFlags receivedFlags, SocketError socketError)
   at System.Net.Sockets.SocketAsyncContext.ReceiveOperation.InvokeCallback()
   at System.Net.Sockets.SocketAsyncContext.AsyncOperation.<>c.<TryCompleteOrAbortAsync>b__14_0(Object o)
   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
   at System.Threading.ThreadPoolWorkQueue.Dispatch()```

PusherOptions property Host is unused

By settings the PusherOptions.Host property you guess that this will redirect the Pusher connection to the correct host (and by that, correct cluster).

This doesn't work and you have to specify the Host property on the Pusher class instead to make this work.

Could not load file or assembly 'System.Configuration.ConfigurationManager

Greetings,

I am having some issues using this lib for .netcore. here is the error. I am using a .netcore 2.0.0-preview1-005977 in macos.

Unhandled Exception: System.IO.FileNotFoundException: Could not load file or assembly 'System.Configuration.ConfigurationManager, Version=0.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'. The system cannot find the file specified.

   at PusherClient.Pusher.Connect()

thank you

Create unit tests

The library presently has no tests. Contributions towards the library in the form of some tests would be very much appreciated.

Pusher crashes when connection is unstable

Pusher crashes when connection is unstable

Exception type: System.InvalidOperationException
Message: Collection was modified; enumeration operation may not execute.
Stacktrace:
at System.ThrowHelper.ThrowInvalidOperationException(ExceptionResource resource)
at System.Collections.Generic.Dictionary`2.Enumerator.MoveNext()
at PusherClient.Pusher.SubscribeExistingChannels()
at PusherClient.Pusher._connection_ConnectionStateChanged(Object sender, ConnectionState state)
at PusherClient.Connection.ChangeState(ConnectionState state)
at PusherClient.Connection.ParseConnectionEstablished(String data)
at PusherClient.Connection.websocket_MessageReceived(Object sender, MessageReceivedEventArgs e)
at WebSocket4Net.WebSocket.FireMessageReceived(String message)
at WebSocket4Net.Command.Text.ExecuteCommand(WebSocket session, WebSocketCommandInfo commandInfo)
at WebSocket4Net.WebSocket.ExecuteCommand(WebSocketCommandInfo commandInfo)
at WebSocket4Net.WebSocket.OnDataReceived(Byte[] data, Int32 offset, Int32 length)
at WebSocket4Net.WebSocket.client_DataReceived(Object sender, DataEventArgs e)
at SuperSocket.ClientEngine.ClientSession.OnDataReceived(Byte[] data, Int32 offset, Int32 length)
at SuperSocket.ClientEngine.SslStreamTcpSession.OnDataRead(IAsyncResult result)
at System.Net.LazyAsyncResult.Complete(IntPtr userToken)
at System.Net.LazyAsyncResult.ProtectedInvokeCallback(Object result, IntPtr userToken)
at System.Net.Security._SslStream.ProcessFrameBody(Int32 readBytes, Byte[] buffer, Int32 offset, Int32 count, AsyncProtocolRequest asyncRequest)
at System.Net.Security._SslStream.ReadFrameCallback(AsyncProtocolRequest asyncRequest)
at System.Net.AsyncProtocolRequest.CompleteRequest(Int32 result)
at System.Net.FixedSizeReader.CheckCompletionBeforeNextRead(Int32 bytes)
at System.Net.FixedSizeReader.ReadCallback(IAsyncResult transportResult)
at System.Net.LazyAsyncResult.Complete(IntPtr userToken)
at System.Net.ContextAwareResult.CompleteCallback(Object state)
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Net.ContextAwareResult.Complete(IntPtr userToken)
at System.Net.LazyAsyncResult.ProtectedInvokeCallback(Object result, IntPtr userToken)
at System.Net.Sockets.BaseOverlappedAsyncResult.CompletionPortCallback(UInt32 errorCode, UInt32 numBytes, NativeOverlapped* nativeOverlapped)
at System.Threading._IOCompletionCallback.PerformIOCompletionCallback(UInt32 errorCode, UInt32 numBytes, NativeOverlapped* pOVERLAP)

HttpAuthorizer returns incorrect auth token

When I run the ExampleApplication I am getting the following error:

"JsonReaderException: Unexpected character encountered while parsing value: S. Path '', line 0, position 0"

Upon further investigation it seems that the error is caused at HttpAuthorizer.Authorize():

authToken = response.Content.ToString();

returns "System.Net.Http.StreamContent" instead of the actual response.

For this to work the line needs to be changed to:
authToken = response.Content.ReadAsStringAsync().Result;

Is this a known issue?

Note: I am using .net 4.6.1

Simple oversight: Small Edit allows for connect again after a disconnect (Websocket issue fix)

I'm really new to github, sorry if this is the wrong place to post this. I could find few other ways to contact the authors.

I discovered a simple issue to fix. I am also new to coding c#, but not new to "coding". The first thing I learned is dispose(); dispose(); dispose();

HAHA

Anyway, The problem I found with the disconnecting loses the websocket access and then it fails to connect again is simply in file Connection.cs : Near Line: 226

        private void websocket_Closed(object sender, EventArgs e)
        {
            Pusher.Trace.TraceEvent(TraceEventType.Warning, 0, "Websocket connection has been closed");

            ChangeState(ConnectionState.Disconnected);
            _websocket.Dispose(); // Line: 226, This is the line I changed. It was ( _websocket = null; )

            if (_allowReconnect)
            {
                ChangeState(ConnectionState.WaitingToReconnect);
                Thread.Sleep(_backOffMillis);
                _backOffMillis = Math.Min(MAX_BACKOFF_MILLIS, _backOffMillis + BACK_OFF_MILLIS_INCREMENT);
                ChangeState(ConnectionState.Connecting);
                Connect();
            }
        }

Otherwise, I have found this PusherClient to work flawless.
Thanks for your time. Hope this helps.

Implement ConnectAsync

Rather than waiting for an event to return, provide a method which will is an awaitable connect.

affect other eventhandler after pusher connect.

i have some problem, my custom event handler won't fire after pusher connect.
i don't know why, but once i mark the line "_pusher.Connect()" then everything went well again.
can't anyone help me??
is that caused by thread??

`
void InitPusher() {
_pusher = new Pusher("KEY", new PusherOptions(){
Cluster = 'ap1'
});
_pusher.ConnectionStateChanged += _pusher_ConnectionStateChanged;
_pusher.Error += _pusher_Error;
_pusher.Connect();
}

private void btn_click(object sender, EventArgs e) {
sklib.OnConnection += new customEventHandler()
}

void sklib_OnConnection(int code) {
if(....)
.....
}
`

Exception handling in IAuthorizer.Authorize

Exception throwing in IAuthorizer.Authorize causes app crash in our WinForms app.
Is there good way to cancel IAuthorizer.Authorize safely?

ハンドルされていない例外: System.Net.WebException: リモート サーバーがエラーを返しました: (401) 許可されていません
   場所 System.Net.WebClient.UploadDataInternal(Uri address, String method, Byte[] data, WebRequest& request)
   場所 System.Net.WebClient.UploadString(Uri address, String method, String data)
   場所 OurApp.PusherListener.OurAppHttpAuthorizer.Authorize(String channelName, String socketId) 場所 APP\PusherListener.cs:行 101
   場所 PusherClient.Pusher.SubscribeToChannel(ChannelTypes type, String channelName)
   場所 PusherClient.Pusher.Subscribe(String channelName)
   場所 PusherClient.Pusher.SubscribeExistingChannels()
   場所 PusherClient.Pusher._connection_ConnectionStateChanged(Object sender, ConnectionState state)
   場所 PusherClient.Connection.ChangeState(ConnectionState state)
   場所 PusherClient.Connection.ParseConnectionEstablished(String data)
   場所 PusherClient.Connection.websocket_MessageReceived(Object sender, MessageReceivedEventArgs e)
   場所 WebSocket4Net.WebSocket.FireMessageReceived(String message)
   場所 WebSocket4Net.Command.Text.ExecuteCommand(WebSocket session, WebSocketCommandInfo commandInfo)
   場所 WebSocket4Net.WebSocket.ExecuteCommand(WebSocketCommandInfo commandInfo)
   場所 WebSocket4Net.WebSocket.OnDataReceived(Byte[] data, Int32 offset, Int32 length)
   場所 WebSocket4Net.WebSocket.client_DataReceived(Object sender, DataEventArgs e)
   場所 SuperSocket.ClientEngine.ClientSession.OnDataReceived(Byte[] data, Int32 offset, Int32 length)
   場所 SuperSocket.ClientEngine.SslStreamTcpSession.OnDataRead(IAsyncResult result)
   場所 System.Net.LazyAsyncResult.Complete(IntPtr userToken)
   場所 System.Net.LazyAsyncResult.ProtectedInvokeCallback(Object result, IntPtr userToken)
   場所 System.Net.Security._SslStream.ProcessFrameBody(Int32 readBytes, Byte[] buffer, Int32 offset, Int32 count, AsyncProtocolRequest asyncRequest)
   場所 System.Net.Security._SslStream.ReadFrameCallback(AsyncProtocolRequest asyncRequest)
   場所 System.Net.AsyncProtocolRequest.CompleteRequest(Int32 result)
   場所 System.Net.FixedSizeReader.CheckCompletionBeforeNextRead(Int32 bytes)
   場所 System.Net.FixedSizeReader.ReadCallback(IAsyncResult transportResult)
   場所 System.Net.LazyAsyncResult.Complete(IntPtr userToken)
   場所 System.Net.ContextAwareResult.CompleteCallback(Object state)
   場所 System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
   場所 System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
   場所 System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
   場所 System.Net.ContextAwareResult.Complete(IntPtr userToken)
   場所 System.Net.LazyAsyncResult.ProtectedInvokeCallback(Object result, IntPtr userToken)
   場所 System.Net.Sockets.BaseOverlappedAsyncResult.CompletionPortCallback(UInt32 errorCode, UInt32 numBytes, NativeOverlapped* nativeOverlapped)
   場所 System.Threading._IOCompletionCallback.PerformIOCompletionCallback(UInt32 errorCode, UInt32 numBytes, NativeOverlapped* pOVERLAP)

Codes:

        public class OurAppHttpAuthorizer : IAuthorizer
        {
            private Uri authEndpoint;
            private string authHeader;
            public OurAppHttpAuthorizer(string authEndpoint, string authHeader)
            {
                this.authEndpoint = new Uri(authEndpoint);
                this.authHeader = authHeader;
            }

            public string Authorize(string channelName, string socketId)
            {
                string authToken = null;

                using (var webClient = new System.Net.WebClient())
                {
                    string data = String.Format("channel_name={0}&socket_id={1}", channelName, socketId);
                    webClient.Headers[HttpRequestHeader.ContentType] = "application/x-www-form-urlencoded";
                    webClient.Headers[HttpRequestHeader.Authorization] = authHeader;
>>>                 authToken = webClient.UploadString(authEndpoint, "POST", data);
                }

                return authToken;
            }
        }

WPF Support

Hi guys, I want to know if this library works with C# WPF apps on the client side. I need to subscribe to a pusher channel from WPF app that runs on windows 10. Keep in mind that the app is a windows classic app, not store app or UWP app. Thanks,

NRE caused by race between Disconnect and automatic reconnect

When the socket is closed externally (i.e. from the remote side closing the connection), the websocket_Closed will dispose/null out the socket, sleep, and try to reconnect.

If a call to Disconnect comes in during the sleep, it will encounter an NRE when it tries to call Close on the null socket, and then the sleeping thread will continue and re-connect the socket.

I can reproduce this fairly consistently in Unity by trying to connect with an invalid key, which seems to make the server close the connection, and then signaling another thread to call DisconnectAsync in the Error event handler.

image

Dynamic code generation from Newtonsoft.Json causes il2cpp incompatibility

I tried to include the latest release in an iOS Unity build, and immediately receive the following exception upon connecting on a device:

NotSupportedException: System.Reflection.Emit.DynamicMethod::.ctor
System.Reflection.Emit.DynamicMethod..ctor (System.String name, System.Type returnType, System.Type[] parameterTypes, System.Type owner, System.Boolean skipVisibility)
Newtonsoft.Json.Utilities.DynamicReflectionDelegateFactory.CreateDynamicMethod (System.String name, System.Type returnType, System.Type[] parameterTypes, System.Type owner)
Newtonsoft.Json.Utilities.DynamicReflectionDelegateFactory.CreateParameterizedConstructor (System.Reflection.MethodBase method)
Newtonsoft.Json.Serialization.DefaultContractResolver.CreateObjectContract (System.Type objectType)
Newtonsoft.Json.Serialization.DefaultContractResolver.CreateContract (System.Type objectType)
System.Func`2[T,TResult].Invoke (T arg)
System.Collections.Concurrent.ConcurrentDictionary`2[TKey,TValue].GetOrAdd (TKey key, System.Func`2[T,TResult] valueFactory)
Newtonsoft.Json.Serialization.JsonSerializerInternalReader.Deserialize (Newtonsoft.Json.JsonReader reader, System.Type objectType, System.Boolean checkAdditionalContent)
Newtonsoft.Json.JsonConvert.DeserializeObject (System.String value, System.Type type, Newtonsoft.Json.JsonSerializerSettings settings)
Newtonsoft.Json.JsonConvert.DeserializeObject[T] (System.String value, Newtonsoft.Json.JsonSerializerSettings settings)
PusherClient.Connection.websocket_MessageReceived (System.Object sender, WebSocket4Net.MessageReceivedEventArgs e)
System.EventHandler`1[TEventArgs].Invoke (System.Object sender, TEventArgs e)
WebSocket4Net.WebSocket.ExecuteCommand (WebSocket4Net.WebSocketCommandInfo commandInfo)
WebSocket4Net.WebSocket.OnDataReceived (System.Byte[] data, System.Int32 offset, System.Int32 length)
SuperSocket.ClientEngine.AsyncTcpSes

It looks like Newtonsoft.Json's DeserializeObject isn't compatible with il2cpp, and the maintainers don't seem to have any intention of fixing it: JamesNK/Newtonsoft.Json#2044

I checked a couple of our Unity projects, and it seems like they're all using the fork linked in the issue above.

I don't have any good proposals for how to fix this. Removing the Newtonsoft.Json dependency and requiring the consumer to provide a deserializer would make the library awkward and unwieldy for non-Unity consumers.

Maybe making a Unity fork is the only reasonable solution?

Calling Disconnect after losing the connection results in an NRE

In Connection.Disconnect, the call to _websocket.Close() invokes the socket closed event before returning. The event handler sets _disconnectionTaskComplete to null, then Disconnect continues and tries to return _disconnectTaskComplete.Task.

I'm not sure about the underlying WebSocket4Net implementation, but this will happen in any scenario where the socket closes synchronously. Connect may also have the same problem, if there's any scenario where the connection completes synchronously.

Unable to recover from a lost connection

If I disconnect my machine from the network after connecting to Pusher, I receive three ConnectionStateChanged events:

  • Disconnected
  • WaitingForReconnect
  • Initialized

When I reconnect to the network, the client doesn't automatically reconnect. If I try to call ConnectAsync to manually reconnect, it returns AlreadyConnected, even though the connection state is Initialized. If I try calling DisconnectAsync before reconnecting, I receive the same result.

From the code, it looks like ConnectAsync can only be called once per instance. I can work around this by recreating my Pusher instance when I lose my connection, but this isn't ideal.

websocket_MessageReceived() Unhandled Exception

Hi,

In PusherClient/Connection.cs , at:
websocket_MessageReceived(object sender, MessageReceivedEventArgs e)

there's no exception handling, and because it happens on different thread - one exception can crash the application!

This is the exception I got:

_System.InvalidOperationException: Collection was modified; enumeration operation may not execute.
at System.ThrowHelper.ThrowInvalidOperationException(ExceptionResource resource)
at System.Collections.Generic.List`1.Enumerator.MoveNextRare()
at PusherClient.EventEmitter.EmitEvent(String eventName, String data)
at PusherClient.Connection.websocket_MessageReceived(Object sender, MessageReceivedEventArgs e)
at WebSocket4Net.WebSocket.ExecuteCommand(WebSocketCommandInfo commandInfo)
at WebSocket4Net.WebSocket.OnDataReceived(Byte[] data, Int32 offset, Int32 length)
at SuperSocket.ClientEngine.AsyncTcpSession.ProcessReceive(SocketAsyncEventArgs e)
at System.Net.Sockets.SocketAsyncEventArgs.OnCompleted(SocketAsyncEventArgs e)
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Net.Sockets.SocketAsyncEventArgs.FinishOperationSuccess(SocketError socketError, Int32 bytesTransferred, SocketFlags flags)
at System.Net.Sockets.SocketAsyncEventArgs.CompletionPortCallback(UInt32 errorCode, UInt32 numBytes, NativeOverlapped* nativeOverlapped)
at System.Threading.IOCompletionCallback.PerformIOCompletionCallback(UInt32 errorCode, UInt32 numBytes, NativeOverlapped* pOVERLAP)

So I think the best way to cover those errors is to catch this at this function.

What do you think?
Thanks.

PusherClient crashes the application

This can happen when Disconnect is called.
The Disconnect() code does UnregisterEventsOnDisconnection() first and then _connection.Disconnect()
If error message comes between these 2 method calls Exception is thrown. There's no code which can handle this exception.

Exception type: PusherClient.PusherException
Message: Invalid key in subscription auth data: '0'
Stacktrace:
at PusherClient.Connection.RaiseError(PusherException error)
at PusherClient.Connection.ParseError(String data)
at PusherClient.Connection.websocket_MessageReceived(Object sender, MessageReceivedEventArgs e)
at WebSocket4Net.WebSocket.FireMessageReceived(String message)
at WebSocket4Net.Command.Text.ExecuteCommand(WebSocket session, WebSocketCommandInfo commandInfo)
at WebSocket4Net.WebSocket.ExecuteCommand(WebSocketCommandInfo commandInfo)
at WebSocket4Net.WebSocket.OnDataReceived(Byte[] data, Int32 offset, Int32 length)
at WebSocket4Net.WebSocket.client_DataReceived(Object sender, DataEventArgs e)
at SuperSocket.ClientEngine.ClientSession.OnDataReceived(Byte[] data, Int32 offset, Int32 length)
at SuperSocket.ClientEngine.SslStreamTcpSession.OnDataRead(IAsyncResult result)
at System.Net.LazyAsyncResult.Complete(IntPtr userToken)
at System.Net.LazyAsyncResult.ProtectedInvokeCallback(Object result, IntPtr userToken)
at System.Net.Security._SslStream.ProcessFrameBody(Int32 readBytes, Byte[] buffer, Int32 offset, Int32 count, AsyncProtocolRequest asyncRequest)
at System.Net.Security._SslStream.ReadFrameCallback(AsyncProtocolRequest asyncRequest)
at System.Net.AsyncProtocolRequest.CompleteRequest(Int32 result)
at System.Net.FixedSizeReader.CheckCompletionBeforeNextRead(Int32 bytes)
at System.Net.FixedSizeReader.ReadCallback(IAsyncResult transportResult)
at System.Net.LazyAsyncResult.Complete(IntPtr userToken)
at System.Net.ContextAwareResult.CompleteCallback(Object state)
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Net.ContextAwareResult.Complete(IntPtr userToken)
at System.Net.LazyAsyncResult.ProtectedInvokeCallback(Object result, IntPtr userToken)
at System.Net.Sockets.BaseOverlappedAsyncResult.CompletionPortCallback(UInt32 errorCode, UInt32 numBytes, NativeOverlapped* nativeOverlapped)
at System.Threading._IOCompletionCallback.PerformIOCompletionCallback(UInt32 errorCode, UInt32 numBytes, NativeOverlapped* pOVERLAP)

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.