vtortola / WebSocketListener

A lightweight and scalable asynchronous WebSocket listener
http://vtortola.github.io/WebSocketListener
312 stars 85 forks source link

websocket server serving url request (or static files) #58

Open ghost opened 8 years ago

ghost commented 8 years ago

1. how the web socket serving static files (URL) ? means: in client javascript: image.src=url1 ;

websocket server: getting the url1 request, and sending back to client the binary image.

2. I tested your vtortola websocket with strings,on concurrent users, it worked perfectly.

any code sample, or link will be appreciated.

vtortola commented 8 years ago

Hi!, the component does not serve HTTP content.

You may want to take a look to HttpListener. The only thing is that you will need to run the websocket server and the http server in different ports.

Cheers.

ghost commented 8 years ago

from your wiki, 1. I think I saw that you give additional protocol http (request,response) so I can serve files additional to websocket (same port) ?

  1. on client javascript image.src=url, what the web socket onMessage is getting ? any string request ?, if yes we can handle this from binary response.
vtortola commented 8 years ago

I think you have seen the part about custom HTTP negotiation, but it is only to hook some logic in case you want to check for example headers like Cookie or Origin and return custom HTTP errors. You cannot use it to serve HTTP content.

You will get nothing. The websocket protocol uses HTTP only for connection establishment and after that it uses its own binary protocol. Even if the browser tries to open a ws connection to the url you put in image.src, it won't try to send a message.

Slyb00ts commented 8 years ago

it still would be really nice to add really simple http communication, for example it could be added like this: http://127.0.0.1 will server http files http://127.0.0.1/socket would serve websockets Please consider this :) BIG THUMBS UP for http static files ;)

vtortola commented 8 years ago

I understand it is something that seems convenient, but definitely this is something I won't add, since it goes beyond the WebSocket spec.

Cheers.

ghost commented 8 years ago

node.js is giving actually :static file serving and stream I also got some info about in other github, that serving static files(images,..) using :back proxy with IIS

jboecker commented 8 years ago

@ellLazar: I was looking for a C# WebSocket server that also had a minimal HTTP server to serve a single-page web app and ended up using https://github.com/sensaura-public/iotweb. Unfortunately, its API does not use async/await (which is why I'd have preferred WebSocketListener).

ghost commented 8 years ago

I also asked this qeustion, on other site how to combine serving websocket and http requests, I have been told it can be achieved by settings reverse Proxy in IIS, and this mechanizm can "steal" the http reuqests. I did not test it, because for me, it's not simple settings.