0

It seems that everybody says that it is possible to send over 126 chars of data over websocket.

I looked at many websocket server examples on the web and non of them can transfer over 126 chars from client to server and from server to client. I understand that it is something with dataframes and opcodes but i never figured it out. I'm using C#.

Can somebody please put some light on this subject? any code example for receiving and sending data over 126 chars will be very very thankful

Cœur
  • 37,241
  • 25
  • 195
  • 267
udidu
  • 8,269
  • 6
  • 48
  • 68
  • 1
    You mean this ? http://stackoverflow.com/questions/8193761/how-can-i-send-larger-messages-over-websocket – Prix Nov 27 '11 at 09:49
  • I posted some pseudocode for any length at http://stackoverflow.com/questions/8125507/how-can-i-send-and-receive-websocket-messages. – pimvdb Nov 27 '11 at 09:53
  • hey pimvdb, i tried your example, actually this is the only one that worked for me but still, its parse only the firxt 126 chars of the message. for example, i used in the client -> websocket.send('hello world'); if the message length is above 126 chars, you example cuts the message and pass only the first 126 chars to the server – udidu Nov 27 '11 at 10:08
  • What's the length of the raw data you're obtaining? Are you sure you're actually receiving all data? – pimvdb Nov 27 '11 at 10:09
  • my data length is 180 chars, my buffer can accept up to 512 bytes – udidu Nov 27 '11 at 10:13
  • @Udi Talias: Could you perhaps post the second byte you're obtaining? That one contains the length, which might not be correct somehow. – pimvdb Nov 27 '11 at 10:26
  • when i do (byte)(buffer[1] & 127) i can get the correct length, but, if i send over 126 chars (say: 180) the (byte)(buffer[1] & 127) returns 126.. ): – udidu Nov 27 '11 at 10:32
  • That's correct, because the length does not fit in that byte when the length is `>= 126`. Please read my answer at "Receiving messages". The next two bytes represent the length. – pimvdb Nov 27 '11 at 10:39
  • I can understand that, but i did exactly what you described in your example and still it didn't worked for me... I will try to do it from the beginning.. maybe i'm missing something... – udidu Nov 27 '11 at 10:50
  • @Udi Talias: Are you perhaps able to dump all raw bytes you're receiving? Then I might be able to see where the algorithm fails in your case. – pimvdb Nov 27 '11 at 11:38

1 Answers1

1

Yes, it's possible. According to the Hybi-10 header docs (unchanged from the current draft proposal):

If payload length from the first payload length section equals 126, you'll read the length from the extended payload length (the following two bytes). If it's 127, you'll read it all the way through the next four bytes to get the full length of the payload (that is, the last six bytes.)

We do it in Alchemy Websockets; you can see how we do it here: https://github.com/Olivine-Labs/Alchemy-Websockets/blob/8ce624b10d82fef6d01b806052d783072b143ba4/src/Alchemy/Handlers/WebSocket/hybi10/FrameHeader.cs

Community
  • 1
  • 1
Jack Lawson
  • 2,479
  • 3
  • 23
  • 24