Hi,

> -----Original Message-----
> From: Mark Thomas [mailto:ma...@apache.org]
> Sent: Thursday, August 27, 2015 12:30 AM
> To: Tomcat Users List <users@tomcat.apache.org>
> Subject: Re: AW: WebSocket asynchronous reads
> 
> On 26/08/2015 12:50, Steffen Heil (Mailinglisten) wrote:
> > Hi
> >
> >
> >>> Is there a way to tell tomcat to stop receiving data for a certain
> >>> websocket?
> >>> (Not to close it, but not to read from inputstream for some time.)
> >
> >
> >> Sorry, no.
> >> The best you can do is a no-op branch in the  message handler.
> >
> >
> > Which means I have to either buffer all incoming messages until I am ready
> to process them (might occupy lots of memory) or I have to drop them.
> > Both is not really ideal.
> >
> > I don’t know, if the websocket specification already defines something, but
> are there any plans to implement such a feature?
> 
> Nothing comes to mind. Sounds like what you really want is reactive streams.
> 
> > From my POV it would be rather easy not to unregister a certain connection
> in the read selector and reregister it later on.
> > However such an API would need to exposed somehow.
> 
> Yes, but such low level access doesn't seem right to me.

I've also thought about that limitation in the Java Websocket API in the past. 
I could imagine to use some form of sleep/wait (e.g. Semaphore.aquire()) in the 
onMessage method to block the thread until it should continue reading. However 
that would of course contradict the aim of asynchronous/non-blocking I/O to not 
block threads while waiting for data.

This is where I like the .Net WebSocket API [1] that is a bit lower-level: It 
provides ReceiveAsync() and SendAsync() methods that allow you to specify when 
you actually want to read from the websocket connection without blocking a 
thread (the ASP.Net API also allows the code in the HTTP pipeline to decide if 
and when a WebSocket/Upgrade request is accepted).

(This could also be useful for forwarding Websocket connections from IIS to 
Tomcat which currently isn't supported by the ISAPI Redirector and the AJP 
protocol - I had been working on a C# SPDY redirector module for IIS but 
haven't yet found time to update it to use HTTP/2 and base it on the new 
modular ASP.Net 5 runtime [2] which will also be officially supported by MS for 
Linux and OS X).

I don't have knowledge about NIO in Java, but for extending the current API I 
could imagine some startReceive() method (as a counterpart to 
RemoteEndpoint.Async#sendText()) using a  sort of callback or just raising the 
onMessage event of the Endpoint as before when data has received (but I suppose 
there are better approaches).


Regards,
Konstantin Preißer


[1] 
https://msdn.microsoft.com/de-de/library/system.net.websockets.websocket(v=vs.110).aspx
[2] https://github.com/aspnet/home


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
For additional commands, e-mail: users-h...@tomcat.apache.org

Reply via email to