Comments (9)
Happy to implement this. I didn't bother as for my uses (communication with a browser's Javascript WebSocket) it didn't seem necessary.
from mbwebsocketserver.
Code would go in - (void)socket:(GCDAsyncSocket *)connection didReadData:(NSData *)data withTag:(long)tag
.
I agree documentation is lacking. I didn't add much as I knew I'd refactor it four times or so. That is pretty much done at this point.
from mbwebsocketserver.
Thanks. I had a small go at doing it myself, but I'm not very knowledgable in bit-shifting so it was slightly over my head.
From what I was reading, Chrome and other browsers support Ping/Pong natively but don't expose it to javascript. So for example, they will automatically respond to a ping without the JS code having to do anything special. Could be useful also for your usage.
The way that I'm planning to use it to to setup a keep alive timer and to automatically disconnect clients if they don't respond in time. This way the server always has an up to date state of each client even if they leave without disconnecting cleanly.
from mbwebsocketserver.
I have this code almost ready to go.
If I understand your request, you also want to actively ping individual clients? As well as have MBWebSocketServer respond to pings they send with a pong?
from mbwebsocketserver.
https://github.com/mxcl/MBWebSocketServer/tree/ping
I'm currently trying to test the pings, but it seems to still work with my app so I'm assuming I didn't break it.
from mbwebsocketserver.
Seems that pings work. Please test and confirm and then I'll merge.
from mbwebsocketserver.
Actively sending Ping
If I understand your request, you also want to actively ping individual clients? As well as have MBWebSocketServer respond to pings they send with a pong?
That's exactly right. For actively pinging clients, I propose the following methods:
// Sends a ping to a client - data may be nil or not nil and is simply echoed back
- (void)sendPing:(NSData *)data connection:(GCDAsyncSocket *)toConnection;
// Delegate callback - data may be nil or not nil depending on the ping that was sent out
@optional
- (void)webSocketServer:(MBWebSocketServer *)webSocketServer didReceivePong:(NSData *)data connection:(GCDAsyncSocket *)connection;
Responding to Ping with Pong
Seems that pings work. Please test and confirm and then I'll merge.
Server responds to Ping, thanks!! (I tested using SocketRocket (iOS WS Client) and added in a ping method from a fork)
from mbwebsocketserver.
Just an update to this, in your current fork of the code it seems to work fine except for the following issue.
Binary data is not received properly - This can be fixed by adding to the message parsing
case 1: // text frame
case 2: // binary frame
case 8: // close frame http://tools.ietf.org/html/rfc6455#section-5.5.1
case 9: // ping frame http://tools.ietf.org/html/rfc6455#section-5.5.2
from mbwebsocketserver.
I think my wip branch handles the binary frames.
I found a test suite and started fixing the class to conform. But I didn't get through all of 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.