CustomSession from Sample issue

May 15, 2011 at 3:32 AM

I've tried to implement the CustomSession from the Samples/CustomSession project in a copy of theSuperWebSocketWeb web project.

The web site starts up without any issue, but when a client tries to connect with websockets (via LiveChat.aspx), I hit the following exception:

System.NullReferenceException was unhandled by user code
  Message=Object reference not set to an instance of an object.
  Source=SuperWebSocket
  StackTrace:
       at SuperWebSocket.WebSocketServer`1.ParseHandshake(WebSocketSession session, TextReader reader) in F:\svn\SuperWebSocket.Codeplex\SuperWebSocket_clean\mainline\SuperWebSocket\WebSocketServer.cs:line 309
       at SuperWebSocket.Protocol.WebSocketHeaderReader.FindCommandInfo(IAppSession session, Byte[] readBuffer, Int32 offset, Int32 length, Boolean isReusableBuffer) in F:\svn\SuperWebSocket.Codeplex\SuperWebSocket_clean\mainline\SuperWebSocket\Protocol\WebSocketHeaderReader.cs:line 39
       at SuperSocket.SocketBase.Protocol.CommandReaderBase`1.FindCommandInfo(IAppSession session, Byte[] readBuffer, Int32 offset, Int32 length, Boolean isReusableBuffer, Int32& left) in e:\Build\SuperSocket\mainline\SocketBase\Protocol\CommandReaderBase.cs:line 75
       at SuperSocket.SocketEngine.SocketSession`2.FindCommand(Byte[] readBuffer, Int32 offset, Int32 length, Boolean isReusableBuffer, Int32& left) in e:\Build\SuperSocket\mainline\SocketEngine\SocketSession.cs:line 113
       at SuperSocket.SocketEngine.AsyncSocketSession`2.ProcessReceive(SocketAsyncEventArgs e) in e:\Build\SuperSocket\mainline\SocketEngine\AsyncSocketSession.cs:line 131
       at SuperSocket.SocketEngine.AsyncSocket.SocketAsyncEventArgsProxy.<>c__DisplayClass4.<SocketEventArgs_Completed>b__0() in e:\Build\SuperSocket\mainline\SocketEngine\AsyncSocket\SocketAsyncEventArgsProxy.cs:line 36
       at System.Threading.Tasks.Task.InnerInvoke()
       at System.Threading.Tasks.Task.Execute()
  InnerException: 
Backing up the callstack, the cast to WebSocketSession seems to be the problem
SuperWebSocketWeb.Protocol.WebSocketheaderReader: FindCommandInfo method (around line 37)
var webSocketSession = session as WebSocketSession; 
WebSocketServer.ParseHandshake(webSocketSession, new StringReader(header));

ParseHandshake will fail at line 309 (session.Items[key] = value;) as session is null, as indicated by the exception trace above.

As per the CustomSession code, session is not a WebSocketSession, but is a SuperWebSocket.Samples.CustomSession.CRMSession
so the cast results a null.

The web.config I used was derived from the Samples/CustomSession/SuperWebSocket.Service.exe.config

Is there something I am missing here - or has anyone else run into this?

 Thanks,

Jim

 

Coordinator
May 15, 2011 at 11:04 AM
Oh, sorry.
Another guy reported a same issue to me, I'll fix it ASAP.

I'll update with you after I fix it.


From: [email removed]
To: [email removed]
Date: Sat, 14 May 2011 20:32:49 -0700
Subject: CustomSession from Sample issue [SuperWebSocket:257660]

From: jstott
I've tried to implement the CustomSession from the Samples/CustomSession project in a copy of theSuperWebSocketWeb web project.
The web site starts up without any issue, but when a client tries to connect with websockets (via LiveChat.aspx), I hit the following exception:
System.NullReferenceException was unhandled by user code
  Message=Object reference not set to an instance of an object.
  Source=SuperWebSocket
  StackTrace:
       at SuperWebSocket.WebSocketServer`1.ParseHandshake(WebSocketSession session, TextReader reader) in F:\svn\SuperWebSocket.Codeplex\SuperWebSocket_clean\mainline\SuperWebSocket\WebSocketServer.cs:line 309
       at SuperWebSocket.Protocol.WebSocketHeaderReader.FindCommandInfo(IAppSession session, Byte[] readBuffer, Int32 offset, Int32 length, Boolean isReusableBuffer) in F:\svn\SuperWebSocket.Codeplex\SuperWebSocket_clean\mainline\SuperWebSocket\Protocol\WebSocketHeaderReader.cs:line 39
       at SuperSocket.SocketBase.Protocol.CommandReaderBase`1.FindCommandInfo(IAppSession session, Byte[] readBuffer, Int32 offset, Int32 length, Boolean isReusableBuffer, Int32& left) in e:\Build\SuperSocket\mainline\SocketBase\Protocol\CommandReaderBase.cs:line 75
       at SuperSocket.SocketEngine.SocketSession`2.FindCommand(Byte[] readBuffer, Int32 offset, Int32 length, Boolean isReusableBuffer, Int32& left) in e:\Build\SuperSocket\mainline\SocketEngine\SocketSession.cs:line 113
       at SuperSocket.SocketEngine.AsyncSocketSession`2.ProcessReceive(SocketAsyncEventArgs e) in e:\Build\SuperSocket\mainline\SocketEngine\AsyncSocketSession.cs:line 131
       at SuperSocket.SocketEngine.AsyncSocket.SocketAsyncEventArgsProxy.<>c__DisplayClass4.<SocketEventArgs_Completed>b__0() in e:\Build\SuperSocket\mainline\SocketEngine\AsyncSocket\SocketAsyncEventArgsProxy.cs:line 36
       at System.Threading.Tasks.Task.InnerInvoke()
       at System.Threading.Tasks.Task.Execute()
  InnerException: 
Backing up the callstack, the cast to WebSocketSession seems to be the problem
SuperWebSocketWeb.Protocol.WebSocketheaderReader: FindCommandInfo method (around line 37)
var webSocketSession = session as WebSocketSession; 
WebSocketServer.ParseHandshake(webSocketSession, new StringReader(header));
ParseHandshake will fail at line 309 (session.Items[key] = value;) as session is null, as indicated by the exception trace above.
As per the CustomSession code, session is not a WebSocketSession, but is a SuperWebSocket.Samples.CustomSession.CRMSession
so the cast results a null.
The web.config I used was derived from the Samples/CustomSession/SuperWebSocket.Service.exe.config
Is there something I am missing here - or has anyone else run into this?
Thanks,
Jim

Read the full discussion online.
To add a post to this discussion, reply to this email (SuperWebSocket@discussions.codeplex.com)
To start a new discussion for this project, email SuperWebSocket@discussions.codeplex.com
You are receiving this email because you subscribed to this discussion on CodePlex. You can unsubscribe or change your settings on codePlex.com.
Please note: Images and attachments will be removed from emails. Any posts to this discussion will also be available online at codeplex.com
Coordinator
May 15, 2011 at 12:21 PM
Thank you for your finding, it is a new bug which was introduced when upgraded SuperSocket to latest version.
Now, I have fixed it. Please update to the latest code.
Thank you again!

May 15, 2011 at 3:33 PM
Thanks for the quick fix, all is working as expected!

This project is looking to be an excellent and very robust implementation of a WebSockets server - I've turned to your project after some experimentation with HTM5Labs WebSockets.

Thank you for all of your efforts!

On 5/15/2011 8:22 AM, kerryjiang wrote:

From: kerryjiang

Thank you for your finding, it is a new bug which was introduced when upgraded SuperSocket to latest version.
Now, I have fixed it. Please update to the latest code.
Thank you again!