tl; diana;
比较它们就像比较餐馆的食物(有时可能很贵,可能不是100%你想要)和自制的食物,在那里你必须自己收集和种植每一种食材。
也许如果你只想吃苹果,后者更好。但如果你想要一些复杂的东西,而你又孤身一人,那真的不值得你自己烹饪和制作所有的食材。
这两种我都用过。以下是我的经验。
套接字IO
Has autoconnect
Has namespaces
Has rooms
Has subscriptions service
Has a pre-designed protocol of communication
(talking about the protocol to subscribe, unsubscribe or send a message to a specific room, you must all design them yourself in websockets)
Has good logging support
Has integration with services such as redis
Has fallback in case WS is not supported (well, it's more and more rare circumstance though)
It's a library. Which means, it's actually helping your cause in every way. Websockets is a protocol, not a library, which SocketIO uses anyway.
The whole architecture is supported and designed by someone who is not you, thus you dont have to spend time designing and implementing anything from the above, but you can go straight to coding business rules.
Has a community because it's a library (you can't have a community for HTTP or Websockets :P They're just standards/protocols)
尚
You have the absolute control, depending on who you are, this can be very good or very bad
It's as light as it gets (remember, its a protocol, not a library)
You design your own architecture & protocol
Has no autoconnect, you implement it yourself if yo want it
Has no subscription service, you design it
Has no logging, you implement it
Has no fallback support
Has no rooms, or namespaces. If you want such concepts, you implement them yourself
Has no support for anything, you will be the one who implements everything
You first have to focus on the technical parts and designing everything that comes and goes from and to your Websockets
You have to debug your designs first, and this is going to take you a long time
显然,你可以看到我偏向于SocketIO。我很想这么说,但我真的真的不想。
我真的在努力不使用SocketIO。我不想用它。我喜欢自己设计东西,自己解决问题。
But if you want to have a business and not just a 1000 lines project, and you're going to choose Websockets, you're going to have to implement every single thing yourself. You have to debug everything. You have to make your own subscription service. Your own protocol. Your own everything. And you have to make sure everything is quite sophisticated. And you'll make A LOT of mistakes along the way. You'll spend tons of time designing and debugging everything. I did and still do. I'm using websockets and the reason I'm here is because they're unbearable for a one guy trying to deal with solving business rules for his startup and instead dealing with Websocket designing jargon.
如果你是一个人的团队或者一个小团队想要实现复杂的功能,那么为一个大的应用程序选择Websockets并不是一个简单的选择。我用Websockets写的代码比以前用SocketIO写的要多,而且比用SocketIO简单十倍。
我要说的是…如果您想要一个成品和设计,请选择SocketIO。(除非你想要一些功能非常简单的东西)