Comments (7)
What is your existing http server?
from fleck.
It's actually a totally custom HTTP server (couldn't find any existing one that fit). It runs in a regular application (e.g. not IIS). It's sort of like Kayak, but Kayak didn't support some of the things I wanted, such as HTTPS.
from fleck.
Fleck doesn't have this available specifically, because its main interface is through the WebSocketServer which aims to open its own socket. However, the parts would likely be composable enough that it could be used. Basically, what you would need is to do something similar to WebSocketServer.OnClientConnect when you detect that a connection is a WebSocket connection.
connection = new WebSocketConnection(
clientSocket,
_config,
bytes => RequestParser.Parse(bytes, _scheme),
r => HandlerFactory.BuildHandler(r,
s => connection.OnMessage(s),
connection.Close,
b => connection.OnBinary(b)));
Create a new WebSocketConnection
object passing it the socket, an initialize action for setting up the callbacks, a function that returns a WebSocketHttpRequest object, and a function for building handlers using that request. Similar to this:
connection = new WebSocketConnection(
new SocketWrapper(existingSocket), //Your socket wrapped with SocketWrapper
_config, //An initializer like the one from WebSocketServer.Start()
bytes => mapToRequest(myrequestobject), //mapToRequest maps your request to a Fleck WebSocketHttpRequest
r => HandlerFactory.BuildHandler(r,
s => connection.OnMessage(s),
connection.Close,
b => connection.OnBinary(b))); //Keep this the same
Hope that helps.
from fleck.
@statianzo I tried this approach and it seems to be almost working. The only problem is that the WebSocketConnection
will wait to receive some data from the socket before calling the request parser handler.
Maybe you could change it to try the request parser even with empty data, and if that fails wait for more data. It already has the code in it to wait for more data, the only addition would be to try the request parser immediately with no data.
I also thought about buffering the HTTP data in my server, and then making a fake ISocket
object that would "replay" the buffered data back for the WebSocketConnection
.
from fleck.
Try calling WebSocketConnection's, CreateHandler
. It has the behavior that will take care of creating a handler and sending the return handshake. I know it's private at the moment, but do it through reflection and if that's all it takes to make it work, I wouldn't have a problem making it public.
from fleck.
OK, I did it! See this gist for the complete code. Making CreateHandler
a public function should help.
from fleck.
That's great. Good work. I'll get the change in to make CreateHandler public soon.
from fleck.
Related Issues (20)
- Handshake SupportedSubProtocols does not work. HOT 3
- How to find out how many connections are connected to a websocket? HOT 1
- Slow Connection Times?
- net::ERR_SSL_VERSION_OR_CIPHER_MISMATCH HOT 2
- Disposing the server when RestartAfterListenError is true may result in a restarted socket
- Memory leak when sending from the server. HOT 1
- Is this project abandoned? HOT 3
- How to get the websocket connecting a client in server.start() HOT 2
- Question: SSL Client Certificate difference HOT 4
- How to let the session close at end of the prosess by OnMessage, disable.
- Server cannot receive binary data with OnBinary if there is OnMessage
- Custom CipherSuite
- Garbled messages from server
- RobiniaDocs API Explorer
- Hi, boss , why don't upgrade new version of Fleck? thx.
- maximum received message size?
- How to stop this websocket service? HOT 1
- How do I close non-websocket connections?
- WebSocketConnetction.SendBytes([]) possible null reference when this.Socket is null
- Write a method to let it not log the information?
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 fleck.