Welcome to Dream.In.Code
Getting C++ Help is Easy!

Join 135,912 C++ Programmers for FREE! Get instant access to thousands of C++ experts, tutorials, code snippets, and more! There are 2,544 people online right now. Registration is fast and FREE... Join Now!




Advantages of multiple sockets

 
Reply to this topicStart new topic

Advantages of multiple sockets

Chirieac
19 May, 2008 - 01:35 AM
Post #1

New D.I.C Head
*

Joined: 8 May, 2007
Posts: 2


My Contributions
Hello! I have a question about sockets:
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?
Bye!
User is offlineProfile CardPM
+Quote Post

Chirieac
RE: Advantages Of Multiple Sockets
19 May, 2008 - 09:30 AM
Post #2

New D.I.C Head
*

Joined: 8 May, 2007
Posts: 2


My Contributions
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!
User is offlineProfile CardPM
+Quote Post

Cerolobo
RE: Advantages Of Multiple Sockets
19 May, 2008 - 09:55 AM
Post #3

D.I.C Regular
Group Icon

Joined: 5 Apr, 2008
Posts: 440



Thanked: 31 times
My Contributions
I'm a bit confused as to what the actual questions are, so this might not be exactly what you wanted.

Anyway, from what I understand, your first question relates to the order that data is received.

CAsyncSocket don't have blocking by default. This means that when you send or receive data, you don't have to wait for all the data to be sent or received before control is returned to your program.

So, if you have two sockets to send data to another computer, and you send a 5MB and a 1MB file at the same time, the 1MB file should be completed first, since it is a lot smaller.

If you enabled blocking for the sockets, then it depends on the order that the files are sent. If you sent the 5MB file first, then your program will send the file, wait for the transfer to complete, and then you would send the 1MB file. The vice versa is true as well.

QUOTE
I really need multithreading?


No, you really shouldn't use multi threading for TCP. Using a nonblocking socket will generally provide better performance, with a lower memory footprint.

QUOTE
But if I send through 2 sockets


Generally, if you are only sending data between two computers, you do not need to have more then one socket. You are more then likely limited based on the computers upload speed. By sending one file at a time, you will reduce the load on the TCP/IP stack, yet the transfer should still finish in about the same amount of time.

User is offlineProfile CardPM
+Quote Post

Reply to this topicStart new topic
Time is now: 12/1/08 07:49AM

Live C++ Help!

C++ Tutorials

Reference Sheets

C++ Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month