Advertisement

multiple sockets

Started by December 16, 2003 02:02 PM
5 comments, last by shadowstryker 21 years, 1 month ago
what do people think the best way for handling multiple socket connections is? at the minute I''m thinking of using the stl vector class to handle them. any suggestions?
The choice of data structures to hold socket descriptors isn''t as important and is dependant on how you plan to use them; single-threaded vs multi-threaded and blocking vs non-blocking vs asynchronous.
Advertisement
One solution is a non-blocking I/O model.

Kuphryn
My current implementation was to create a class that contained a blocking/non-blocking socket and methods that each socket would use. What I''ve done is to create them in an std::vector

I just wondered if anyone had better ideas.
It depends on the design. Other solutions for storing socket objects include a map, a set, an a hash-table.

Kuphryn
ok, what I''ve done is to create a vector called conx of type SesSocket (where SesSocket is a class that holds various winsock related commands) such that it holds all the connections that are created.

conx.push_back(SesSocket(port));std::vector::iterator itr = conx.begin();itr->setBlocking(0,false);itr->acceptSession();std::cout << itr->uPort << std::endl; 


The above code is a brief version of what I''ve used to attempt this, and includes some debugging information.

Out of that code the following lines do not work:
itr->setBlocking(0,false);itr->acceptSession(); 


Though the line that prints the variable called uPort does work, which means that a SesSocket is pushed onto the vector, though for some reason the Winsock related commands do not.

The code for setBlocking() and acceptSession() have been tested outside the vector and work fine.


Does anyone have any idea what is causing this and how it might be fixed?
Advertisement
I''ve fixed it :D

It was due to the socket not initialising as it was supposed to :s

This topic is closed to new replies.

Advertisement