multiple sockets
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.
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.
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
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.
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:
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?
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?
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement