xkothe
xkothe

Reputation: 674

TCP Multiple Connections vs 1 connection (Application Managing)

I need some advice... I'm building a desktop application where every window needs constant input from the user (events like click, typing, mouse move) to be sent to the server. The server also sends constant feedback like (refresh some data in the dialog, text, new objects, etc)

First I thought I would use HTTP, but now choose to use plain TCP.

My question is: Should I use one TCP connection and handle all info from the server at "Application Layer", or should I create multiple connections (like one for each window and let the OS handle the multiple TCP pipes) ?

I can programming any of these 2 ideas, but who would be more efficient in terms of performance and bandwidth?

Update 1

Upvotes: 2

Views: 1339

Answers (1)

KillianDS
KillianDS

Reputation: 17176

This depends too much on your specific application, but where possible I'd pick multiple connections, it has multiple advantages:

  • No head-of-line blocking between multiple components (windows in your case).
  • Multiprocessing/multithreading available even on socket layer (e.g. you can have 1 thread/socket).
  • You don't need to build a multiplexer protocol atop of TCP yourself.

The only reasons why you wouldn't want to do this:

  • You're short on ephemeral ports. This is usually not an issue unless you're talking about tens of thousands of long-lived sockets or you're working behind some very restrictive NAT device.
  • The OS overhead (memory/processing power) per socket is non-neglible. I'd be surprised if this would be true for any decent modern OS, but measuring is knowing.

Upvotes: 1

Related Questions