Modern solution to WebSocket servers? - c#

For my website I wrote a WebSockets server in C# (most preferred language to code in) that uses Fleck and it's approximately 600 lines of code. Everything seems to be working decently (a little unstable at times though. Not sure if it's a problem with my code or Fleck).
However, I want to move this from my computer to an actual domain and I'm not sure if there are any hosting providers that would support .NET console applications like that.
I was thinking that maybe I would have to rewrite it in another language like PHP but I'm slightly unsure about the whole idea. Are there any popular hosting providers that would support what I am looking for? And even if they are, is it such a good idea? I imagine it may be less secure or slower than the typical solution of using Perl, PHP, or Python for servers. (lots of P's)
Lastly, if it was a good idea to rewrite, I'm not sure of which language I would write it in. It's been a while and I'm not sure what everyone still uses. Is PHP still considered to be the most supported and secure for web servers?
Which WebSockets implementation is best suited? It took me a while to find Fleck and there seem to be twice as many PHP derivatives and I'm feeling a bit overwhelmed again. Also, a lot of posts on Stackoverflow about WebSockets are from two years ago when they were not as supported.
Sorry for my naivete and lack of focus in my question but as you can see I'm a bit confused as to what my course of action here should be and I'm looking for some insight. Thanks for reading.

Probably the most popular WebSocket server is Socket.IO. It is implemented in Node (Javascript) and has fallbacks to long-polling/AJAX when WebSockets support is not available.
The most well supported implementation of WebSockets is the python pywebsocket project which is used by both Mozilla and Google for developing and testing their client browser implementations. In addition, pywebsocket is designed to easily integrate with Apache allowing you to run your web server and websocket service on the same port(s).
If your application just needs a WebSocket based messaging service and is largely peer-to-peer you might consider using a commercial WebSocket service like Pusher. That could save you from having to host and manage your own server for this.
I would not recommend PHP for WebSocket servers. Until recently there wasn't a PHP implementation that supported both the older and newer WebSocket protocol variation. The older is still used by current iOS devices and the newer IETF 6455 version of the protocol is used by Chrome, Firefox, IE10 and the Flash based WebSocket polyfill web-socket-js.
Also, you ask if PHP is still considered to be the most supported and secure for web servers. Certainly, PHP has always had great documentation and examples and very wide deployment so you could argue it's well supported. However, PHP falls near the bottom of the list in terms of security. I would certainly not rewrite your application from scratch in PHP.
If you are partial to C like languages, you might consider libwebsockets which you could use to build a C or C++ WebSocket server. Andy Green developed and maintains libwebsockets and participated in the IETF working group that developed the standard.
Ruby is another language/community that has seen a lot of uptake of WebSockets (perhaps second behind Node). The most popular websocket library for Ruby is em-weboskcet.

you can try node.js, is "new" and it look good.
Regards

Related

Which socket serverside software for video conferencing?

I want to create a simple video conferencing site and at the beginning I have decided to use Microsoft's SignalR with Mono and apache. But there are some voices saying that SignalR is slow. And if that's true it might be even worst on Mono in linux.
That's why i decided to come here and seek your help. There are a few projects like:
1. Microsoft's SignalR
2. xSockets
3. Microsoft.WebSocket
4. SuperWebsocket
I would like to ask if any of you have any experience with this projects and could help me chose between them.
Thanks in advance!
Disclaimer: I work at XSockets.
I would use OHM's law in combination with what hosting you are planning.
With XSockets and SuperWebSocket you will have support for full-duplex communication (websockets) on all server platforms.
SignalR and Microsoft.WebSockets require Win8+/2012 Server and IIS8 to be able to provide websockets on the server. If you use another platform you will get half-duplex techniques (SSE, Longpolling...) See supported platforms
Maybe that is why you ask about SignalR being slow since you will run on Linux and that means that you will not get WebSocket-support from the server when using SignalR/Microsoft.WebSocket?
When it comes to implementation both SignalR and XSockets has implementations of WebRTC (I assume that it is WebRTC you are talking about event though you do not mention it). I have no idea if SuperWebSocket has any WebRTC samples, but you should be able to port the samples of SignalR and XSockets to SuperWebsocket if you want to.
When it comes to client support there is obviously the issue with IE, but Chrome, FF and Opera will support WebRTC in desktop. On mobile you will have support on Android, but on iOS you will need something like this Cordova lib
It is tested with XSockets webrtc implementation, but I cant speak for others. Should work with the SignalR implementation as well, but we have not tried that.
So, IMHO you should choose between 1,2 and 4 depending on server platform and the implementation that suits your project the best.
Option 3 is probably not a good choice at all...
EDIT:
A link to a WebRTC sample
Here is a project that uses SignalR for video conferencing.
Now, unless you provide the sources saying that SignalR is slow, I can't really have much to say, except that it depends on your scenario. Have a look at the introduction to SignalR and see if your project fits.
If you really want to use Mono and Apache, you will face some compatibility issues, since ASP.NET doesn't have a stable release on Linux, and SignalR will not make the first release of ASP.NET 5.
Unless there is no other option, I would go with IIS for hosting an ASP.NET application until Microsoft releases the cross-platform framework.
As of SigalR being slow, I really don't know what this is about (how many users, what is the behaviour of this 'slow', when sending, or when receiving messages?).
Hope this helps. Best of luck!
EDIT: Ok, have a look at this repo, give it a try and see if you have issues. As for the other technologies listed, I didn't work with them, so I can't really help you.

Implementing a Web Service Server in Windows CE 2013

I have a smart device (Windows CE 2013) that just got the requirement to be controlled from a number of different devices, to do this, we decided to serve a web page from the device that allows it to be controlled.
I've also read that compact framework doesn't support ASP.NET so I'm intending to serve a static webpage that contains a javascript application that calls web services hosted on the device.
I also found this link explaining how to serve a SOAP Service in C++, but it seems old, and I'd prefer to do this in C# as it's my preffered language and I already have some code on it
I'm not quite happy with this solution, am I missing something? Can't I really do this in C#?
You could try this library for .NET https://github.com/ServiceStack/ServiceStack .
It is a free in case if you are using branch v3 form a github.
There's nothing built-in in the CF that provides web server capability. Windows CE has always shipped with an HTTPD server, but, honestly, it sucks and can't be integrated with managed code anyway.
We solved this problem long ago by creating our own IIS-like web server implementation (available commercially). You could do something similar as well - it's just a lot of Socket work. That trivializes the complexity of concurrent request handling and providing an IIS-like object model, but you get the idea. Basically you have to write the whole thing.
The main answer to this is to use Mongoose (or the MIT-licenced equivalent Civetweb). They are C webservers designed for just your task - an embedded web server.
They are really easy to implement, 1 C source file added to your project, give it an array of options, and you're done. See the examples. It has plenty of features and is fast, and small (40kb compiled!). They say it takes 5 minutes to get going with it, and they're right - I tend to use it to add webserver functionality for normal applications now.

How to write an client-server video streaming

I'm working on project that will work real time: I have to write a video streaming client-server app, this server will to send the AVI/MPEG etc to an web application. I have some questions:
What is the protocol recommend to do this, http? rtp? or other?
In the web application, how do I to show it to user? using an flash player,java applet(I don't ensure if it's possible with it) or HTML5, what is the best way to do this currently?
I hope this is clean for you. Any help is very appreciadted. Thanks in advance. :)
There are several different ways to implement this (some that require programming and others that don't). Which one you choose depends on your requirements.
Red5 is an obvious solution which will allow you to only have to focus on the web side as long as your player of choice is flash.
FlourineFx provides a similar environment for .NET with a little more effort.
I've also done this with IIS and a custom server using HttpListener with much success if you're set on a pure Windows/C# solution. The caveat I'd add here is that it isn't always simple. In an environment with limited throughput, you will have problems since HTTP doesn't have the time corrections that RTP/RTMP/RTSP have but in a decent network it works 3 9's of the time (I've only tested with a single player though).
UPDATE
If you're talking about live streaming with .NET I'd suggest looking into the DirectShow (or related DirectX) API's. There is a wrapper for it for .NET available called DirectShow.NET.

TCP/IP vs Web Services for iPhone chat app

How to create a NATIVE chat app for the iPhone? So far we have been exploring a few options:
Creating a web service using php or other web based language and have the app connect to that. Only problem is we can't figure out how to create "push" messaging with this, where the user will not have to refresh the conversation constantly.
Hosting an application on a server such as Windows Azure which will communicate to the iPhone app using TCP/IP. This way it seems like "push" messaging could be achieved by simply sending a packet to the iPhone. However, we have never done this before and don't know if we would run into any unforeseen potholes.
Have any of you made such an app before? If so how did you go about doing it? If not, what method would you recommend?
Thank you in advance!
EDIT:
To tell you exactly what we're trying to do: we need to make an app where a user can join a chat room and send/ receive messages from that chat room. There will also be custom features like that users will have their own profiles, etc. We would also like to make this as flexible as possible, so that we can integrate it on other platforms like android and blackberry later on.
So essentially the part that I'm stuck on is the send/ receive messages from a chat room. What technology should we use server side?
Something with an open socket, like Socket.IO could work. Node.js is a good server-side framework to explore. Here's an related SO question: iPhone Objective-C socket communication with Socket.IO
EDIT:
Question has changed since posting this answer -- originally question asked about web apps. ALso, originally the question was not clear that you wanted answers about the server side more than the client side.
On the server side, I would still recommend Node.js -- sounds like you want to use C# though, which makes me wonder why you're asking again about what server side tech to use. Most languages will provide you with ways to connect a socket to a client and access a database, which are the two main requirements of the app that it sounds like you want to make. Use whatever language you're comfortable with. However, some are going to come with libraries that may come in handy for this type of communication -- Node.js and Ruby on Rails (more useful if you want to do a polling-based solution)
Look at http://code.google.com/p/cocoaasyncsocket/ for a good library for doing socket communication from the iPhone without having to delve too deep into the low-level functions.
I've done this several times. Scaling to 100K concurrent users is non-trivial. If you want an off-the-shelf system I suspect ejabberd may do what you want. although the protocol IMHO is too verbose and uses far more bandwidth than necessary.
If you want to write your own solution and have the flexibility to write your own protocol and have the maximum possible scalability in the future then use a language that allows you to distribute the application across several servers. It is easier to allow that from the get go rather than writing a single server solution then have to retroactively make it distributable.
Having written servers like this in c++, Java and Erlang I would say the easiest and most relevant tool was Erlang. It makes good use of multi core processors and with a good design it facilitates distributing across several servers. C++ was the hardest!
I have also used Java with tools like JETTY and RabbitMQ to write a highly scalable system that required using HTTP as the protocol.
Personally I prefer a custom binary protocol as it allows you to reduce bandwidth to a minimum, and avoids DOS attacks and such as the protocol is well defined and lengths are sent before the packet, where as non binary protocols need to be parsed as they come in, with no idea of how big the packets may be.
Why not try XMPP protocol first? XMPP is based on TCP/IP.
There are several OpenSource server solution, clients, and application libraries. XMPP already supports chat room like service. You can define extension easily.

C# NET Server/Client Application

I am starting on a fairly basic Server/Client application (logic wise), but I am a bit confused as to what I should use for my needs. It looks like there a few options, but basically I am going to have a Master Server, and X amount of client applications (one per dedicated machine). The main purpose of this setup is so that I can basically do the following...
-Issue command to server (console app) via an ASP front end to install software on one of the remote clients.
- Server tells client to download zip package (from a various FTP site) to location and extract it to specific path.
I am not positive, but it looks like C# has Sockets and then some sort of WebClient type of deal. I am assuming Sockets would be the best route to take, and to use asynchronous (each remote client is connected in its own thread, dealing with the server individually of others).
Any information on this would be great!
Without going into too much detail for your specific requirements, I would definitely look at WCF.
It encompasses a lot of the existing remoting, client / server, web services scenarios in a very complete and secure framework.
Client Server Programming with WCF
WebClient allows you to make HTTP requests, so I don't think it's very relevant here.
There are many approaches you can take for this app.
One is of course going with WCF, which provides about a million time more options than you will need. However, WCF does have a learning curve and in particular it's hard to understand what exactly is hidden behind all the abstractions without prior experience. Furthermore, this solution is not available if you are targeting .NET 2.0.
You can also implement a simple TCP client/server model using sockets. While you can program against raw sockets, .NET also offers the convenience classes System.Net.Sockets.TcpListener for the server and System.Net.Sockets.TcpClient for the clients. This approach is much closer to the metal, but this is a tradeoff: it's much easier to understand what exactly you are doing, but you will have to implement a fair bit of functionality yourself.

Categories