NetGain icon indicating copy to clipboard operation
NetGain copied to clipboard

Documentation and Comments

Open NVentimiglia opened this issue 9 years ago • 23 comments
trafficstars

Some very basic documentation defining the key features of NetGains would be nice. Looking at the code I see support for HeartBeat (kicking dead connections), an serverside interface for handling disconnections, authentication, and messages. I also see a UserToken, is this some sort of client session? Its hard to tell because none of the methods have comments.

Also maybe a WebApi / MVC serverside demo would be nice

NVentimiglia avatar Feb 18 '16 07:02 NVentimiglia

A JavaScript demo would also be nice. The library looks like a really promising alternative to SignalR which is somewhat heavy and has a dependency on jQuery still baked in it for JavaScript clients.

lbacaj avatar Feb 19 '16 14:02 lbacaj

What I'm hearing is: "we need to see an end to end typical use case". I get that. This seems a reasonable request. Any suggestions for examples? Maybe a very simple chat style application (no storage, auth, etc)?

On Fri, 19 Feb 2016 14:50 Luljan Bacaj [email protected] wrote:

a javascript demo would also be nice.

— Reply to this email directly or view it on GitHub https://github.com/StackExchange/NetGain/issues/3#issuecomment-186243299 .

mgravell avatar Feb 19 '16 23:02 mgravell

@mgravell yeah that would be awesome. Like @Ibacaj I am looking for something like SignalR without the bloat which makes SignalR completely unusable for game development.

For my case I need a concept of channels / groups (send to a subset of users). and Presence (broadcasting when a user disconnects). Looking at the code, I noticed the Broadcast method accepted a func for sending to select users. I also noticed the heartbeat. Am I correct to assume this is a possibility for NetGain ? If so, it would be great if you included this.

Not needed, but nice to have would be some sort of user state. Something like userName, I didnt see an extensible point for the connection, maybe there is another way ?

You mentioned Auth and storage. Agree they are not needed, but some pointers on how to go about this (Dos and Donts) would always be welcome.

Also, I would be happy to help with a demo on the client side (Xamarin or Unity or Mvc or whatever) once a interface is ready.

NVentimiglia avatar Feb 20 '16 05:02 NVentimiglia

A simple chat client with user to user communication, and examples with SSL would be nice.

pjanning avatar Feb 22 '16 15:02 pjanning

Re state: that is all built in; there is an object (UserToken) that you can stick anything you like on, and populate at auth time.

Broadcast can indeed be used to talk to a great many nodes; you can pass a predicate that returns a message or null to not notify that client. Alternatively, if you track individual connections, you can just send explicitly to the ones that interest you.

We use NetGain as part of chat.SE, so it all sounds possible.

What we DO NOT currently support is SSL (wss). We haven't needed to. I'd be open to pull requests that added that, but at the moment we use raw sockets, not a Stream, so it would be quite a significant piece of work to do that. I wonder whether that is something that would be better handled by haproxy or similar, if possible.

On 22 February 2016 at 15:37, pjanning [email protected] wrote:

A simple chat client with user to user communication, and examples with SSL would be nice.

— Reply to this email directly or view it on GitHub https://github.com/StackExchange/NetGain/issues/3#issuecomment-187234269 .

Regards,

Marc

mgravell avatar Feb 22 '16 15:02 mgravell

@mgravell is this UserToken shared between client and server or will I need to come up with a handshake ?

NVentimiglia avatar Feb 22 '16 16:02 NVentimiglia

I am looking forward to see examples. :) Depending on your implementation WSS/SSL isn't needed. Do you have more informations about chat.SE?

pjanning avatar Feb 22 '16 16:02 pjanning

I have a non-working sample. I may be doing something wrong on the client side, I'm not a native JS speaker.

https://github.com/NVentimiglia/NetGain/tree/master/StackExchange.NetGainWebChat

My exact error is

SyntaxError: Failed to construct 'WebSocket': The URL '127.0.0.1:6002' is invalid.

Ill try again later

NVentimiglia avatar Feb 29 '16 02:02 NVentimiglia

SyntaxError: Failed to construct 'WebSocket': The URL '127.0.0.1:6002' is invalid.

Try to use 'ws://127.0.0.1:6002' as URL. This should work.

pjanning avatar Feb 29 '16 07:02 pjanning

WebSocket connection to 'ws://127.0.0.1:6002/' failed: Error in connection establishment: net::ERR_CONNECTION_REFUSED

That got me further. My firewall is off, anything else you can think of ?

Edit

Worked fine when I ran the console app independent of the web app. It would be nice to run within the web app for prototyping without a VM.

NVentimiglia avatar Feb 29 '16 16:02 NVentimiglia

@mgravell Is there any way to handle onconnect / ondisconnect serverside ?

NVentimiglia avatar Mar 01 '16 03:03 NVentimiglia

The typical usage would be to subclass WebSocketsMessageProcessor; this then allows you to override various methods, including methods that relate to each WebSocketConnection (as a parameter), such as:

OnOpened OnAuthenticate OnAfterAuthenticate OnClosed OnShutdown

Does that answer the question?

On 1 March 2016 at 03:34, Nicholas Ventimiglia [email protected] wrote:

@mgravell https://github.com/mgravell Is there any way to handle onconnect / ondisconnect serverside ?

— Reply to this email directly or view it on GitHub https://github.com/StackExchange/NetGain/issues/3#issuecomment-190523784 .

Regards,

Marc

mgravell avatar Mar 01 '16 08:03 mgravell

@rherwig and me built a little example with NetGain. Here are our Repositories:

https://github.com/pjanning/NetGain-ChatExample/ (Backend) https://github.com/rherwig/websocket-chat (Frontend build with React)

pjanning avatar Mar 02 '16 07:03 pjanning

nice; awesome stuff

On 2 March 2016 at 07:46, pjanning [email protected] wrote:

@rherwig https://github.com/rherwig and me built a little example with NetGain. Here are our Repositories:

https://github.com/pjanning/NetGain-ChatExample/ (Backend) https://github.com/rherwig/websocket-chat (Frontend build with React)

— Reply to this email directly or view it on GitHub https://github.com/StackExchange/NetGain/issues/3#issuecomment-191114403 .

Regards,

Marc

mgravell avatar Mar 02 '16 09:03 mgravell

@mgravell I have one question. Why don't you need WSS at StackExchange?

pjanning avatar Mar 10 '16 09:03 pjanning

In a perfect world, we'd probably make use of it, but basically we considered:

  • wss is awkward to implement from the technical perspective, especially if you are working from the socket layer, not the stream layer (so: you can't just use SslStream)
  • tying our web-socket server security into the primary site security (with rotating cookies and all that goodness) is awkward
  • we don't want to send big payloads to unattended browsers
  • we deploy the web-socket server very rarely, contrast to the web-site which we deploy very frequently; since we want the UI elements (and any associated data) to reflect the up to date site, it makes sense to let the web-site deal with that (assuming it can't be done trivially in javascript)

So basically, in our scenario, the optimum approach seems to be: only broadcast a "hey, there's more stuff you should know" (not the actual stuff, just a hand wave "hey you!" - no PII in there, note). Trivially simple (and public) stuff like rep / voting: we just update on screen from that, but in most cases we display a notification to the user that new stuff is available (which could be a red inbox envelope, or a "new questions / answers are available" banner). When the user actually clicks on that, we use regular AJAX to our main site with our regular security model etc.

In other scenarios, I totally agree that wss would be not just desirable but necessary. The problem is: it isn't a small amount of work to do it!

Now; on a related note, I suspect that if we want to move to .net core, some massive changes (aka basically a rewrite) would be necessary. Whether that is sensible or not, I don't know at this point - it could well be that the reduced API surface in .net core means that it simply doesn't scale in the way we need. And there are now more and better tools in this space than existed when we first wrote this. But hypothetically, if we were gutting it for .net core purposes that forced us to use different APIs, that might also be a good time to consider wss. Or maybe it isn't! But I certainly can't think of any clean way to implement it right now.

mgravell avatar Mar 10 '16 10:03 mgravell

@pjanning To expand on that, @NickCraver has reminded me that we do use wss, but: not at the library level. We terminate that at the NLB (haproxy). The library does not support wss, but it can still be done externally. We didn't use wss initially, hence the above.

mgravell avatar Mar 10 '16 10:03 mgravell

To add to the WSS discussion, because this is important: we don't use WSS for security at Stack Overflow. Nothing of a secure nature is sent over them.

We use WSS because a great many (especially older) proxies on the internet do not handle websockets connections correctly. While most of these will totally screw up an unencrypted websocket connection, they'll happily pass along an encrypted connection they don't understand. It's a "bad proxy" workaround in our case, and for many others out there.

NickCraver avatar Mar 10 '16 11:03 NickCraver

Thank you for your answers. @NickCraver, @mgravell

I was really confused, how you could use NetGain at StackExchange. If i set up an Webpage which is accessed via SSL. I have to use WSS. Otherwise i would not get an connection. Your solution to use a proxy for this sounds good. Thank you!

pjanning avatar Mar 12 '16 23:03 pjanning

How does this http://vtortola.github.io/WebSocketListener/ fit against NetGain ?

jalchr avatar Nov 09 '16 21:11 jalchr

@pjanning @mgravell This repository no longer exists https://github.com/rherwig/websocket-chat

Any hints about how are you sending initial data (for example, username or so ) on initial connection (for example onOpen or On Authenticate) ? Or I'm getting this totally wrong, and I'll have to wait until "OnReceive" to get an useful identification from the client ?!

jalchr avatar Nov 11 '16 08:11 jalchr

@mgravell If the user failed to authenticate at "OnAuthenticate", how can I shut down the connection from the server ?

jalchr avatar Nov 11 '16 08:11 jalchr

@mgravell

WebSocketsMessageProcessor

How do you use the WebSocketsMessageProcessor as a subclass?

yhydra avatar Dec 13 '18 21:12 yhydra