Coder Social home page Coder Social logo

Comments (8)

statianzo avatar statianzo commented on September 13, 2024

Could you set the FleckLog.LogLevel to debug and attach the output here?
On May 20, 2012 10:35 PM, "arct" <
[email protected]>
wrote:

When testing the jWebSocket Android client "fundamental" demo apk, the
client can connect with Fleck, but closes the connection upon sending a
message. No onMessage event is fired at the Fleck server.


Reply to this email directly or view it on GitHub:
#41

from fleck.

arct avatar arct commented on September 13, 2024

5/21/2012 6:46:20 PM [Info] Server started at ws://localhost:8080 (Fleck server started)
5/21/2012 6:46:23 PM [Debug] Client Connected (jWebsocket Android client opens connection)
5/21/2012 6:46:23 PM [Debug] 236 bytes read
5/21/2012 6:46:23 PM [Debug] Building Hybi-14 Response
5/21/2012 6:46:23 PM [Debug] Sent 129 bytes (Fleck server waits for message)
5/21/2012 6:46:28 PM [Debug] 69 bytes read (jWebSocket Android client sends message)
5/21/2012 6:46:28 PM [Debug] Error while reading Fleck.WebSocketException: Exception of type 'Fleck.WebSocketException' was thrown.
at Fleck.Handlers.Hybi13Handler.ReceiveData(List1 data, ReadState readState, Action2 processFrame)
at Fleck.Handlers.Hybi13Handler.<>c__DisplayClassa.b__5(List1 d) at Fleck.Handlers.ComposableHandler.Receive(IEnumerable1 data)
at Fleck.WebSocketConnection.<>c__DisplayClassb.b__a(Int32 r)
at Fleck.SocketWrapper.<>c__DisplayClassb.b__9(Task1 t) at System.Threading.Tasks.Task1.<>c__DisplayClass17.b__16(Object obj)
at System.Threading.Tasks.Task.InnerInvoke()
at System.Threading.Tasks.Task.Execute()
5/21/2012 6:46:28 PM [Debug] Sent 4 bytes (jWebsocket Android client closes connection)

from fleck.

statianzo avatar statianzo commented on September 13, 2024

The source of the exception is this line. It's designed to ensure that an incoming frame is valid. If an invalid frame is received, an exception is thrown and the connection is closed.

if (!isMasked
    || !Enum.IsDefined(typeof(FrameType), frameType)
    || reservedBits != 0 //Must be zero per spec 5.2
    || (frameType == FrameType.Continuation && !readState.FrameType.HasValue))
    throw new WebSocketException(WebSocketStatusCodes.ProtocolError);

It's not passing one of the checks. It's possible that jWebsocket isn't matching spec. I would say that dropping a breakpoint on this conditional and finding the failing expression would be your best bet as to determining the cause of the error. Would you mind doing that?

from fleck.

arct avatar arct commented on September 13, 2024

I added watches for each operand in that expression and set a breakpoint there. After stepping through to the exception, they evaluated as follows:

!isMasked : TRUE
!Enum.IsDefined(typeof(FrameType), frameType) : FALSE
reservedBits != 0 : FALSE
(frameType == FrameType.Continuation && !readState.FrameType.HasValue) : FALSE
WebSocketStatusCodes.ProtocolError = 1002

It appears jWebSocket Android client does not mask frames when sending. That's probably the culprit, because I don't think that's compliant behavior per RFC 6455. Am I correct?

from fleck.

statianzo avatar statianzo commented on September 13, 2024

That's correct. RFC 6455 states both of the following:

If the data is being sent by the client, the frame(s) MUST be masked as defined in Section 5.3.
The server MUST close the connection upon receiving a frame that is not masked.

If you're interested in helping jWebSocket, the masking algorithm is quite simple, and a C# implementation exists here.

public static byte[] TransformBytes(byte[] bytes, int mask)
{
    var output = new byte[bytes.Length];
    var maskBytes = BitConverter.GetBytes(mask);
    if (BitConverter.IsLittleEndian)
        Array.Reverse(maskBytes);

    for (int i = 0; i < bytes.Length; i++)
    {
        output[i] = (byte)(bytes[i] ^ maskBytes[i % 4]);
    }

    return output;
}

from fleck.

arct avatar arct commented on September 13, 2024

Thank you for your help.

from fleck.

WirawanBagus avatar WirawanBagus commented on September 13, 2024

Has this problem been solved? Because I see the same problem now. .

from fleck.

statianzo avatar statianzo commented on September 13, 2024

the issue seemed to be with jwebsocket. best to check there.

from fleck.

Related Issues (20)

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.