Comments (3)
I found that the issue was with SocketRocket sending a duplicate header with different keys, so nothing to do with this project. The issue is as follows, the handshake gets sent twice (for whatever reason) and MBWebscketServer only processes the first handshake instead of the latest one.
Although not directly a bug in this project, it would be good to add a little bit of logic to check for multiple instances of the handshake and only process the last one. This would make it much more robust. I'll submit some code tomorrow for this.
See below for duplicate header:
GET / HTTP/1.1
Host: localhost:8001
Origin: http://localhost:8001/
Sec-WebSocket-Key: KO3jnDW54UHeLHiAscOF2Q==
Upgrade: websocket
Connection: Upgrade
Sec-WebSocket-Version: 13
GET / HTTP/1.1
Host: localhost:8001
Origin: http://localhost:8001/
Sec-WebSocket-Key: 4L5fa8w2NqxQeLKs4Y9JZQ==
Upgrade: websocket
Connection: Upgrade
Sec-WebSocket-Version: 13
from mbwebsocketserver.
For anybody else who encounters this problem, here's my fix which only fixes the problem if there's duplicate headers sent:
Pass the string to new method in handshakeResponseForData:(NSData *)data after the string is created
// MBWebSocketServer.m
NSString *string = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
// This is a check to see if there are duplicate headers
[self fixDuplicateHeader:&string];
Add this method to MBWebSocketServer.m to remove any duplicate header
// MBWebSocketServer.m
- (void)fixDuplicateHeader:(NSString **)headerString {
// Setup
NSString *lastHandshake = @"";
NSString *getStr = @"GET / HTTP/1.1\r\n";
NSScanner *scanner = [NSScanner scannerWithString:*headerString];
[scanner scanUpToString:getStr intoString:&lastHandshake]; // Scan all characters before GET str
if (lastHandshake) {
while (![scanner isAtEnd]) {
[scanner setScanLocation:([scanner scanLocation]+getStr.length)];
//[scanner scanString:@"GET / HTTP/1.1\r\n" intoString:nil]; // Scan the GET str
[scanner scanUpToString:getStr intoString:&lastHandshake]; // Scan all characters before next GET str
}
*headerString = [NSString stringWithFormat:@"%@%@",getStr,lastHandshake];
NSLog(@"[Server] Removed a duplicate header sent from client");
}
}
from mbwebsocketserver.
We should handle this properly, even if SocketRocket is behaving badly to trigger it.
from mbwebsocketserver.
Related Issues (5)
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from mbwebsocketserver.