Sockets or Threading Problem ?

Started by
14 comments, last by Thunder Sky 16 years, 11 months ago
actually, i dont know what u mean by select, explain more please. send your code if you have time. kimocono1986@hotmail.com

[Edited by - RockySabre on May 6, 2007 5:07:49 PM]
Advertisement
I've worked a bit with WinSock a while ago. That was in C++, Im not sure how similar it is to C#. Select() takes a pointer to some struct (I believe) and a socket as its arguments and fills the struct with information about the sockets current state (if it has data waiting to be read etc). It is a blocking function and will not return until the socket is in a state other than "idle". Hope that helped, was a while back so Im not sure how acurate this is (and I never acctually used select, I went with nonblocking recvs).

I have a question of my own; why do people want to use several threads and sockets to send a single file? granted, sending too big packages might not be good but couldnt you just send a small one (or rather one with "apropiet" size), wait, and then send another one. I havnt bothered to realy look into it, but it seems that bitTorrent clients use this multiple tread/socket aproach. Why?

cheers
Thunder Sky
well you use multiple sockets/threads so you can download different parts of the file from different sources at the same time. My problem is when there are alot of threads transfering data, will this affect the speed of sending and receiving the packets a big deal ? and if there another way to know that the remote socket is disconnected other than Socket.Select(...) i wanna know it also. Any help will be appreciated, thnx.
Sent the server and client source in a 37k rar. You can have the server running and up to 4(can be changed) client programs running. If you open a 5th client, it will receive a "server full message"

If you close a client window without telling the server to disconnect you (bye typing "exit"), the server handles it properly.

As for a little help on Select, this link would explain it better than me.

http://msdn2.microsoft.com/en-us/library/system.net.sockets.socket.select.aspx
my blog contains ramblings and what I am up to programming wise.
Quote:I have a question of my own; why do people want to use several threads and sockets to send a single file? granted, sending too big packages might not be good but couldnt you just send a small one (or rather one with "apropiet" size), wait, and then send another one. I havnt bothered to realy look into it, but it seems that bitTorrent clients use this multiple tread/socket aproach. Why?


Torrents open many connections.

Single threaded aproach for high traffic applications breaks down (stalls) quickly.

Threading allows for much better load balancing.

Keep in mind, torrent doesn't send a single file, it sends hundreds of chunks to possibly hundreds of clients.

I should have expained a bit more. Naturaly if you want to send/recv to/from several other clients you need more than one socket. What I ment was "why are several sockets used when sending to a single client". But I guess you kind of answered that: in case on socket breaks down the clients can continue exanging data without having to wait for the socket to be closed properly then connected again. right?

This topic is closed to new replies.

Advertisement