HTTP or Websocket for a low latency web game?

I am new to web development and I just want to find out what a performance comparison is.

I create a battle in Tetris on the Internet. Most game logics are inside a server that is built in C ++. For clients, I plan to use cocos2d-js, which is basically javascript.

The behavior of players will affect opponents. Firstly, the user input must correctly enter the server, the server applies the input to the logic, and it will send a new game state to the clients. The client should only present sprites on the screen.

My initial plan was to implement it using a TCP socket, as it might require low latency. However, I just realized that we are not using a TCP socket on the Internet.

Can I use an HTTP connection for such an application? Should I try a web socket? What are the pros and cons?

+4
source share
2 answers

You can, of course, use HTTP for this, but for real-time exchange, the best option is to use websockets.

Raw sockets (aka TCP sockets) are not part of the W3C standard . Despite the fact that some browsers implement them , I would recommend not using them if you do not care about blocking your application in this particular browser.

, Websockets , ​​ , , JS. , ++- , , , this , .

, /, Node.js Socket.io , . , Socket.io protocol, ++, .

Raw (TCP)

  • : ++
  • : , (-), , ..

WebSockets

  • : TCP,
  • : , , .

TCP .

: -, TCP- W3C, API- ( ), - ( Chrome ).

+5

, @Sosdoc . , , libarary, SignalR, websockets. , ++ signalr-qt github: https://github.com/p3root/signalr-qt

0

All Articles