kerryjiang / SuperWebSocket

SuperWebSocket is a .NET implementation of WebSocket server.
Apache License 2.0
504 stars 194 forks source link

Sending a second message from client to server fails #6

Open KBeoughter opened 10 years ago

KBeoughter commented 10 years ago

Using the latest source from Github for SuperSockets, SuperWebSockets, WebSocket4Net and SuperSocket.ClientEngine I can open a connection from a Client to a server (WebSockets) and send as many message from the server to the client that I want. However whenever I try to send more than one message from the client to the server connection is closed.

I have track this down to a change you made in "SuperSocket/SocketBase/AppSession.cs".

You added the line "var currentRequestLength = m_ReceiveFilter.LeftBufferSize" to the "FilterRequest" method (line 504 in the latest version on github). When this method is called for the second message sent from the client m_frame used in the property get method, LeftBufferSize, is null and causes a null reference exception to occur. Note, the first time it is not null.

I was able to work around this by checking for null in the LeftBufferSize property get method. I don't think this is a good solution since I think what you are trying to handle large data frames being sent from a client and my "kludge" won't do that.

kerryjiang commented 10 years ago

If so, there must be an exception logged. Could you send me the error log?

KBeoughter commented 10 years ago

[System.NullReferenceException] = {System.NullReferenceException: Object reference not set to an instance of an object. at SuperWebSocket.Protocol.WebSocketDataFrameReceiveFilter.get_LeftBufferSize() in v:\Code\src\Mono\SuperWebSocketServerLibrary\SuperWebSocket\SuperWebSocket\Protocol\WebSocketDataFrameReceiveFilter.cs:line 24 at SuperSocket.SocketBase.AppSession2.FilterRequest(Byte[] readBuffer, Int32 offset, Int32 length, Boolean toBeCopied, Int32& rest, Int32& offsetDelta) in v:\Code\src\Mono\SuperWebSocketServerLibrary\SuperSocket\SocketBase\AppSession.cs:line 504 at SuperSocket.SocketBase.AppSession2.SuperSocket.SocketBase.IAppSession.ProcessRequest(Byte[] readBuffer, Int32 offset, Int32 length, Boolean toBeCopied) in v:\Code\src\Mono\SuperWebSocketServerLibrary\SuperSocket\SocketBase\AppSession.cs:line 562 at SuperSocket.SocketEngine.AsyncSocketSession.ProcessReceive(SocketAsyncEventArgs e) in v:\Code\src\Mono\SuperWebSocketServerLibrary\SuperSocket\SocketEngine\AsyncSocketSession.cs:line 241

From: Kerry Jiang [mailto:notifications@github.com] Sent: Monday, January 20, 2014 11:16 AM To: kerryjiang/SuperWebSocket Cc: Beoughter, Ken [PROCESS/PSS/AUS] Subject: Re: [SuperWebSocket] Sending a second message from client to server fails (#6)

If so, there must be an exception logged. Could you send me the error log?

— Reply to this email directly or view it on GitHubhttps://github.com/kerryjiang/SuperWebSocket/issues/6#issuecomment-32778654.

kerryjiang commented 10 years ago

Which version of SuperSocket are you using? You can find the information from the assembly property.

The current SuperWebSocket code in master branch is compatible with SuperSocket 1.6.*. If you want to use the latest code of SuperSocket, please download the code in the branch v1.6 of SuperSocket.

KBeoughter commented 10 years ago

I am using the latest source available on GitHub.

The version I see is 1.7.0.0 for all of the SuperSocket dlls (right click on the dll, select properties then click the details tab).

Ken

From: Kerry Jiang [mailto:notifications@github.com] Sent: Tuesday, January 21, 2014 8:11 AM To: kerryjiang/SuperWebSocket Cc: Beoughter, Ken [PROCESS/PSS/AUS] Subject: Re: [SuperWebSocket] Sending a second message from client to server fails (#6)

Which version of SuperSocket are you using? You can find the information from the assembly property.

— Reply to this email directly or view it on GitHubhttps://github.com/kerryjiang/SuperWebSocket/issues/6#issuecomment-32887755.

kerryjiang commented 10 years ago

Please use the source code in the branch "v1.6". I have fixed the exception for SuperSocket 1.6.1. I also upgraded the SuperSocket in the reference folder of SuperWebSocket to the latest version of 1.6. So what you only need do is getting the latest source code of SuperWebSocket from the repository.

KBeoughter commented 10 years ago

Kerry,

The reason I went to the newer version was to resolve an issue I was having with ipv4 and ipv6. The issue I was seeing was when I tried to open a websocket connection it would fail stating an improper URL was being using. I track this down to a socket is being created for both ipv4 and ipv6 with the ipv6 being the first one created. The ipv6 socket creation would fail and we’d never get to create the ipv4 socket. I found that if I commented out the creation of the ipv6 socket then it would work.

I think I’ll stick to the current source I’m using with the kludge I added since the project I am using this on is for research only and not for a product intended for released. I’ll keep my eye on these projects and probably upgrade when I see a new version released.

By the way which do you recommend using, CodePlex or GitHub? To me it seems you keep GitHub more up to date with your changes but CodePlex appears to be your more stable release…

Thanks, Ken

From: Kerry Jiang [mailto:notifications@github.com] Sent: Tuesday, January 21, 2014 9:00 AM To: kerryjiang/SuperWebSocket Cc: Beoughter, Ken [PROCESS/PSS/AUS] Subject: Re: [SuperWebSocket] Sending a second message from client to server fails (#6)

Please use the source code in the branch "v1.6". I have fixed the exception for SuperSocket 1.6.1. I also upgraded the SuperSocket in the reference folder of SuperWebSocket to the latest version of 1.6. So what you only need do is getting the latest source code of SuperWebSocket from the repository.

— Reply to this email directly or view it on GitHubhttps://github.com/kerryjiang/SuperWebSocket/issues/6#issuecomment-32892048.

kerryjiang commented 10 years ago

It seems a client side issue, you don't need struggle with the server side code. I remember this issue, it is in the SuperSocket ClientEngine which WebSocket4Net depends on.

kerryjiang commented 10 years ago

After I checked the code, I don't think there is a problem existing.

The client will try next ip address resolved from the host if the first ip address cannot be reach.

KBeoughter commented 10 years ago

Kerry,

Here is the exception I am seeing when I run my applications using Mono 3.2.3

Unhandled Exception: System.Net.Sockets.SocketException: An address incompatible with the requested protocol was used.

at System.Net.Sockets.Socket..ctor (AddressFamily addressFamily, SocketType socketType, ProtocolType protocolType) [0x00000] in :0 at SuperSocket.ClientEngine.ConnectAsyncExtension.CreateAttempSocket (SuperSocket.ClientEngine.DnsConnectState connectState) [0x00000] in :0 at SuperSocket.ClientEngine.ConnectAsyncExtension.OnGetHostAddresses (IAsyncResult result) [0x00000] in :0

If I run my executables as standard windows apps then they work as expected…

To get my application to run using Mono 3.2.3 I have to modify the file “SuperSocket.ClientEngine/Common/ConnectAsyncExtension.Net40.cs” commenting out the code as follows…

static partial void CreateAttempSocket(DnsConnectState connectState) { //if (Socket.OSSupportsIPv6) // connectState.Socket6 = new Socket(AddressFamily.InterNetworkV6, SocketType.Stream, ProtocolType.Tcp);

if (m_OSSupportsIPv4) connectState.Socket4 = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); }

Note: With the above modification my application will run using Mono 3.2.3 or as standard window app.

FYI: My developer machine is running Windows 8.1 and I compile using Visual Studio 2012 with update 4 applied.

Ken

From: Kerry Jiang [mailto:notifications@github.com] Sent: Thursday, January 23, 2014 7:51 AM To: kerryjiang/SuperWebSocket Cc: Beoughter, Ken [PROCESS/PSS/AUS] Subject: Re: [SuperWebSocket] Sending a second message from client to server fails (#6)

After I checked the code, I don't think there is a problem existing.

The client will try next ip address resolved from the host if the first ip address cannot be reach.

— Reply to this email directly or view it on GitHubhttps://github.com/kerryjiang/SuperWebSocket/issues/6#issuecomment-33124887.