Search code examples
c#asp.netwcfsystem.net.sockets

Net.Sockets, WCF or ASP.NET for a real-time chat


I want to implement my idea, develop an application that will have client/server sides and make connection of clients to server, so they will be able to transfer messages in real-time.

So i will develop using C#, but the question is : what should i use? I dont know what method will be better for that chat. I need to choose between Net.Sockets, WCF and ASP.NET. So I ask you to help me with choise. If I use ASP.NET, I'll have to play with selfhost things, because I don't want to create a site, or something like this to use chat.


Solution

  • Firstly, let's start from your variants

    1. Net.Sockets are too low level. It's hard to make acceptable protocol. But you can use existing protocol - WebSockets. There is a tutorial how to write websocket server on c#: https://developer.mozilla.org/en-US/docs/Web/API/WebSockets_API/Writing_WebSocket_server

    2. Possibly, if you choose WCF, you can try to use WCF duplex persistent connection over netTcpBinding. It's easily to make self-hosting WCF-service. But WCF is complex and I think it's significant overhead for simple tasks. Also, as I know duplex connection works by using long polling, which wastes a lot of resources. Choose this variant carefully.

    3. ASP.NET. If you are talking about MVC or Web Api you should use long polling, which wastes a lot of resources and isn't real realtime

    There are another variant - ASP.NET SignalR (which works using WebSockets)

    1. Here you can look how to write client: https://github.com/SignalR/SignalR/wiki/SignalR-Client
    2. And here you can find tutorial on self-hosting of SignalR: http://www.asp.net/signalr/overview/deployment/tutorial-signalr-self-host