Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.
Sign upWebsocket support. #2
Comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
cheako commentedAug 3, 2017
I was working on Tor2web, a client of twisted web. I discover that to move forward I'd need iResponce to expose the socket or something to read/write on. Once it's necessary to edit twisted-web I might as well go all out and at least partially implement Websockets.
Here is what I did for Tor2web It's incomplete, I was reading twisted-web and discovered the masked interface. Here is a good reference for Websockets at a protocol level, it does say server but if you'r not working in Javascript this is the document u need to read.
Here is what I'd envision for an interface, knowing only a little Python and almost no twisted.
Upon receiving the response headers indicating a change of protocol(connection: upgrade). Remove the socket from any connection pool, as it can't ever be used for http. The connection will be upgraded until it's closed.
Expose a socket interface in the iResponse class, it could be the class itself or an attribute. This could be a copy of the twisted socket interface or even that interface itself. With at least.
a. onRead callback.
b. Write.
c. Close.
d. onClose callback.
e. onError, ect.
The api does not NEED a method to determine if the connection was upgraded, since the headers indicate as much. However to prevent attempts to access the Websocket API when it's not available a python(ish) method for detecting as much I'll leave to your discretion.
Thank you.