Link to home
Start Free TrialLog in
Avatar of thready
thready

asked on

Bidirectional nature of sockets

Hi Experts,

Please correct me if I'm wrong on any of this and maybe throw in some goodies?

I would like to set up a client and server that communicate over a socket.  It is my understanding that I can write or read to this socket at any time, thus, the client and server may both contain a read and write thread (so 4 threads if client and server happen to be on the same machine).  Is is ok if the read thread polls and reads every so often while the write thread writes?  i.e., on one socket, are there two separate channels that don't affect eachother at all?

Thank you!
Mike
ASKER CERTIFIED SOLUTION
Avatar of Mike Tomlinson
Mike Tomlinson
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of thready
thready

ASKER

Excellent!  With option 2, it complicates termination/shutdown a lot though right?  How would you terminate that elegantly?
Avatar of thready

ASKER

Just a timeout I guess- within the read (within the loop)?
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of thready

ASKER

ambience, I agree with you, but I'm looking at a maximum of about 6-8 threads.  I have data-intensive reads and writes and I want them setup on a live socket that exists for the lifetime of each pair.  Once communication starts, there's a lot of data that goes back and forth and it's a bit in the need for speed.  If the connection is established, I only want to do that once.  I still need time to mull over the answers...  Thanks everyone!
>>  I have data-intensive reads and writes and I want them setup on a live socket that exists for the lifetime of each pair.  Once communication starts, there's a lot of data that goes back and forth and it's a bit in the need for speed.

Single thread per socket isnt necesarily going to be faster; there are so many factors that each would affect. I dont think any of the Reactor or IO completion based design would result in slowdown either. Depending upon how intelligent the internal design is the Reactor may sort of starve some sockets if say socket at index 0 is always active (has IO). But like I said, it depends upon the internals.

Threaded servers on the other hands are somewhat easier to code (though easy is a relative term).
Avatar of thready

ASKER

I'm trying to find out which library to use that would simplify the client to use sockets with.  My goal is to have a bread-and-butter standard c++ socket on the client side.  Does anyone know if I use the standard library for sockets, so that I can easily drop this code into an iPad project as well as on a windows machine inside a native MFC application?
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of thready

ASKER

POCO- right.  You said the magic word!  I really like POCO - I'll have to give it a try that way.
Avatar of thready

ASKER

Thanks everyone for the terrific help!