Operating System - Linux
1748182 Members
3527 Online
108759 Solutions
New Discussion юеВ

Re: threaded sockets in C++

 
msbinu
Advisor

threaded sockets in C++


Hi All ,

I m trying to write a clinet server program
My problem is that I want my server to be alwys listening to a port and also should be able to handle Simultaneous connection requests
Can any one give be some hints as to how to do this in C++( threaded sockets )

Regards
Binu
4 REPLIES 4
Arunvijai_4
Honored Contributor

Re: threaded sockets in C++

Hi Binu,

You can try these links,

http://squirl.nightmare.com/medusa/async_sockets.html
http://www.cs.wustl.edu/~schmidt/cs544/socket2.html

Also, Assign points.

-Arun
"A ship in the harbor is safe, but that is not what ships are built for"
rick jones
Honored Contributor

Re: threaded sockets in C++

How about marking the sockets non-blocking and using select() or poll() (or eventports)?
there is no rest for the wicked yet the virtuous have no pillows
msbinu
Advisor

Re: threaded sockets in C++

Thanks ARun,Rick

Can I do some think like this
While(true)
{
sd = accept (listen_sd, (struct sockaddr*) &sa_cli,(int *) &client_len);
//trying to create threads
if(sd)
{
pthread_create(&ThreadA,pthread_attr_default,connection,&sd);
}
rick jones
Honored Contributor

Re: threaded sockets in C++

In broad handwaving terms, yes, but frankly, a thread per connection is overkill. It may be easier to code, but in terms of efficiency, I'm hardpressed to see where non-blocking I/O and select/poll wouldn't win-out. The only case would be if there was something one had to do per-connection that couldn't be done non-blocking.
there is no rest for the wicked yet the virtuous have no pillows