Skip to content

WebSocketServer.Broadcast throws NullReferenceException v1.6.6.1 #249

Description

@darxis

I am using the SuperSocket.WebSocket NuGet package version 1.6.6.1.

The following code:

var sessions = _webSocketServer.GetAllSessions().ToList();
_webSocketServer.Broadcast(sessions, serializedMessage, (session, sendOk) =>
            {
                if (!sendOk)
                {
                    try
                    {
                        session.Send(serializedMessage);
                    }
                    catch
                    {
                        PolicyHelper.TryOnce(() => session.Close(CloseReason.SocketError));
                    }
                }
            });

sometimes throws NullReferenceException.

Also, could you please tell me if I am using the sendFeedback parameter correctly? I want to make sure that the message is broadcast, so if sendOk is false then I just manually call the session.Send(serializedMessage) method to make sure it will get send (I have observed cases when the sendOk was false and the WebSocketSession was connected and healthy).

I just want to make sure that the message will be broadcast to all clients, so I have to check the sendOk param. Wouldn't it be better if WebSocketServer.Broadcast internally used a new method
void WebSocketSession<TWebSocketSession>.SendRawData(IList<ArraySegment<byte>> segments)
instead of the current
bool WebSocketSession<TWebSocketSession>.TrySendRawData(IList<ArraySegment<byte>> segments)?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions