0

I am developing TCP server in C++(win32/linux) which cater multiple client.The server is for Video Streaming.Client request video to server and Server get it from Gateway connected with camera. I am stuck up in the class Design.I found three classes by

  1. Peer
  2. Session and
  3. ConnectionMgr.

So here ConnectionMgr is responsible for managing other Classes.

I wanted your feedback on this.

  1. what info Peer and session need to have;
  2. How Peer and session is related
  3. what information needs to be modeled here.
  4. how to do Session maintainer.
  5. Managing multiple client will require Threads what information thoses may need.

Please give your feedback so that I can upgrade my design.

7
  • 1
    why TCP for video streaming? Intuitively I'd use UDP for that Commented Mar 9, 2011 at 6:51
  • Thats the requirement. In fact I will Add UDP functionality later by adding NAT traversal Technique.NAT traversal won't work in all cases.So I am adding TCp functionality as well. Commented Mar 9, 2011 at 6:54
  • 2
    Why don't have peek at boost::asio and check out how those guys did their corresponding design? Just to get some ideas. Or even better, use the boost::asio classes :-) boost.org/doc/libs/1_46_0/doc/html/boost_asio/reference.html Commented Mar 9, 2011 at 7:03
  • I need to develop in pure C++.anyway I will go through it. Commented Mar 9, 2011 at 7:07
  • 2
    Chris_vr: There is no such thing as "pure" C++. You need some libraries to do anything and boost works on all common platforms. In fact, writing portable code using boost is much easier than "pure" C++, because the system API for both network and threads is very different between Win32 and Unix. Commented Mar 9, 2011 at 7:44

2 Answers 2

2

Looking at the problem space from scratch:

  • there's some state associated with each client that connects - you seem to split this between Peer and Session and I see no real value in that if they're 1:1 - can omit such trivia from the high-level design stage.
    • "what info Peer and session need to have": socket descriptor is the only crucial thing, assuming you have only one camera and stream to all clients at the same pace (losing data when socket send() blocks/can't complete due to full buffer), otherwise, a buffer too...
  • you have a ConnectionMgr, well - yes... it must listen and accept clients on the server socket, possibly launch a new thread per client or monitor the set of current client connections and dispatch events
  • you'll need to make some decisions about the I/O and concurrency model (e.g. select/poll/non-blocking, async, blocking, single threaded, thread-per-client, thread-pool etc)
    • this will obviously affect your design: you should decide which - or which choices - you need to support...

To get a feel for this problem space, I suggest you create a very simple client/server program - probably using threads if you're familiar and comfortable with multithreading, otherwise you can hack upon the GCC libc TCP client/server examples for a select() based solution (http://www.gnu.org/s/libc/manual/html_node/Server-Example.html#Server-Example) or try boost::asio or ACE or whatever. To start, just get it working so you can telnet to the server and whatever you type in any connection is echoed out on all the connections. That should give you enough insight to start asking more concrete questions.

Sign up to request clarification or add additional context in comments.

2 Comments

1.You mean to say Session and Peer classes are not required 2.Here There each client is associated with different gateway.It is like Private Video Streaming.Each gateway is having Unique number.Normally Mapping between Clinet and Gateway is 1:1.but if any clinet want to share video in that case mapping will n:1.Launching per client thread is confusing.what will happen if there is 1000 client accessing simluteanosly will it work.
If you have 1000 clients accessing the same video stream, then you probably want to react to the receipt of new video data by engaging at most one or two threads per CPU core to each write the data to their share of the client connections. That's likely to do it more or less as fast as the OS can manage without much wasteful overheads. So, you wouldn't necessarily want a thread per client pulling the data. Still, the best idea with these things is to write elegant code that lets you reconfigure quickly and cleanly to benchmark these alternatives.
2

As @nabulke and @Jan Hudec stated in their comments, Boost.Asio is very good solution for your problem. Have a look at pretty simple example "Async TCP Echo Server". It uses just 2 classes: server and session. No session_manager. Sessions are managed automatically by smart pointers, very convenient and simple approach.

Using Boost.Asio you can keep the network part simple (and almost optimal by efficiency using asynchronous processing). As a bonus, adding couple of code lines, you receive multithreaded server w/o headache (I would recommend this example: "An HTTP server using a single io_service and a thread pool calling io_service::run().", just ignore HTTP stuff. pay attention to boost::asio::io_service::strand used in connection class)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.