Click here to Skip to main content
15,888,113 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
thanks for these quick responds .
I will try this time to clarify everything regarding the multithreaded server.
we were asked to implement a TCP server single or multithreaded "but the multithreaded will gain more credits",this TCP server has to connect to a client which is given as .exe file by the professor"i have no access for the code", the server should respond to the client requests which are echo ,reverse echo ,time stamp , synchronise and error.
just to mention that we are using three libraries "winsock.dll , WS2_32 AND WSOCK32"
if (connSock  = listener->Accept(client_addr)){
            ThreadData *data = new ThreadData ( this,
                                                connSock,
                                                client_addr );
            DWORD pth1 = _beginthreadex( NULL,
                                         0,
                                         ThreadedTCPServer::thread,
                                         data,
                                         0,
                                         &thID );
        }
        else
            break;

this is the part were I start the new thread and it will be handled by new connector socket not the same listner socket ...
so now if i try to check if its working properly i just added cou<<connsock;
but it was the same for each client that connects to the server .
all I am asking now is "how can I check if my code running as multithreaded or not ?? and if its multithreaded then do I have to use Roundrobin , Semaphore or Mutex ??and for what shall I use them because as far as i can tell i dont need to schedule the CPU because the each client connect to the server and send request to the server and recieve response and disconnect right away. if you need more details please dont hesitate to ask any questions.
Posted
Updated 28-Dec-10 1:53am
v4
Comments
eng.spidy 27-Dec-10 16:05pm    
by the way if you need to see my source code I am ready to post it but I am not sure if this is legal according to the website policy
JF2015 27-Dec-10 17:39pm    
Edited to improve readability.
Dalek Dave 27-Dec-10 18:37pm    
Source code is allowed.
Sometimes obligatory, people will need to see it in order to help.
BUT! Don't do a code dump, just post the region giving the problem, as people hate trawling through 300 lines of code to fine the bug.

1 solution

A multi-threaded server is expected to be superior to a single threaded one in the sense that it can handle multiple requests from clients simultaneously. I don't see how can those two programs 'handle the same amount of clients'.

Try adding some reasonably heavy calculation in the handler of socket receive event. The single-threaded server will be bogged down, while the multi-threaded one will continue to serve.

Your friend is probably not creating and running sockets on threads himself, but is using a library which does that for him.

More importantly, with this post of yours, it is not even clear what you want help with.
 
Share this answer
 
Comments
eng.spidy 29-Dec-10 0:30am    
i updated the question please check it out if you still need more details just ask me so i can clarify it for you many thanks

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900