Click to See Complete Forum and Search --> : Advantages of multiple sockets?
Chirieac
May 18th, 2008, 05:47 PM
Hello!
I want to capture the desktop every 500 milisec and send it over the net. But I want to send every 200 milisec the frames from a webcam too. Should I use 2 different socket for sending/receiving: one for desktop and one for webcam? If will use 2 different sockets I will receive the images faster? I mean that if I send first 2 desktop images and after that 1 webcam frame, I will receive the webcam frame even if I don't received those 2 images? Or there is no point in using multiple sockets?
Bye!
Chirieac
May 19th, 2008, 05:16 AM
To be more precise:
If I send through one socket 5mb of data and then 1mb, on the other end I will receive the 1mb data after I receive those 5mb.
But if I send through 2 sockets: first 5mb data through first socket and then through the other socket 1mb. If on the other side I have 2 sockets too, one to receive those 5mb and one to receive that 1mb, when I will receive the second data (that 1mb)? Still after I receive those 5mb?
Chirieac
May 19th, 2008, 01:23 PM
I think I need multithreading (at least on the client side).
I've made some tests on a single computer like this:
1. Server listening on 2 different ports (of course with 2 sockets). The client has also two socket: one for each port to connect. If I send from the server through one socket 20mb and through the other 8 bytes, on the client I'm still receiving first the 20mb and then the 8 bytes.
2. If I connect to the server with 2 apps (one app for each port) and I send like above (first 20mb to one app and the 8 bytes to the other) I receive first the 8 bytes in one app and then the 20mb on the other app.
So the problem is in receiving the data.
Solution: one socket on different thread I think it should work, since threads are like processes (more or less). I will handle the OnReceive function for each socket in it's own thread. (I'm using CAsyncSocket class for my sockets.)
Now, I want to say sorry for my post. I shouldn't have post it before I've made some tests myself. The post should have been like this: "Here's what I found so far. Are my tests right? I really need multithreading?"
In the future I hope I will make smarter posts.
Bye!
Edders
May 20th, 2008, 05:44 AM
Hello, I'd like to chime in here... My instinct tells me to use two different sockets for the two different types of data that you want to transport. The benefit of using two distinctive sockets is that the network layer will sort the data for you.
Of course you can use one single socket to transport both the desktop info as well as the web cam image, but that means that you will have to identify which data is which so that the receiver knows which data packet is which. When you use two sockets then you do not need to do that. Using two sockets makes it much easier to use two threads as well, which (on the current multi-core processors) will make sense to do.
The downside might be synchronizing the two independent streams, but that may not really be necessary if a difference of (say) a second does not really matter to you.
Regardless of using one or two sockets, you can also build in a priority system when there is a congestion issue on the network. You could then let the system decide not to send the next packet of one of the streams so that you use less bandwidth on the network.
Chirieac
May 20th, 2008, 01:15 PM
Thanks Edders for your reply! I will see... Bye!
codeguru.com
Copyright 2007 Jupitermedia Corporation All Rights Reserved.