How does client data go to sub thread of the server rather than original listening thread?
up vote
0
down vote
favorite
My question is about client server communication in the following scenario.
A server listens on port 21 and is capable of serving multiple incoming connections simultaneously from clients (C1, C2 and so on ) without blocking them
So when a client C1 connects to server S on the port 21 the server accepts the connection on main thread and creates a new thread TH1 and let it handle the client request while the main thread starts listing to port 21 again to accept new clients.
TH1 sends some data back to client C1,
C1 reveives the data and send more data to the server on the same connection which was establisehd on port 21.
This data arrives at server and is received by thread Th1 while the main the main thread of Server continues to listen on port 21.
My question is how does the further data sent by client C1 on the same connection which was made on port 21 automatically goes to the thread Th1 ? even though the main thread of server is listening on port 21 for new connections ?
multithreading tcp network-programming client-server
add a comment |
up vote
0
down vote
favorite
My question is about client server communication in the following scenario.
A server listens on port 21 and is capable of serving multiple incoming connections simultaneously from clients (C1, C2 and so on ) without blocking them
So when a client C1 connects to server S on the port 21 the server accepts the connection on main thread and creates a new thread TH1 and let it handle the client request while the main thread starts listing to port 21 again to accept new clients.
TH1 sends some data back to client C1,
C1 reveives the data and send more data to the server on the same connection which was establisehd on port 21.
This data arrives at server and is received by thread Th1 while the main the main thread of Server continues to listen on port 21.
My question is how does the further data sent by client C1 on the same connection which was made on port 21 automatically goes to the thread Th1 ? even though the main thread of server is listening on port 21 for new connections ?
multithreading tcp network-programming client-server
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
My question is about client server communication in the following scenario.
A server listens on port 21 and is capable of serving multiple incoming connections simultaneously from clients (C1, C2 and so on ) without blocking them
So when a client C1 connects to server S on the port 21 the server accepts the connection on main thread and creates a new thread TH1 and let it handle the client request while the main thread starts listing to port 21 again to accept new clients.
TH1 sends some data back to client C1,
C1 reveives the data and send more data to the server on the same connection which was establisehd on port 21.
This data arrives at server and is received by thread Th1 while the main the main thread of Server continues to listen on port 21.
My question is how does the further data sent by client C1 on the same connection which was made on port 21 automatically goes to the thread Th1 ? even though the main thread of server is listening on port 21 for new connections ?
multithreading tcp network-programming client-server
My question is about client server communication in the following scenario.
A server listens on port 21 and is capable of serving multiple incoming connections simultaneously from clients (C1, C2 and so on ) without blocking them
So when a client C1 connects to server S on the port 21 the server accepts the connection on main thread and creates a new thread TH1 and let it handle the client request while the main thread starts listing to port 21 again to accept new clients.
TH1 sends some data back to client C1,
C1 reveives the data and send more data to the server on the same connection which was establisehd on port 21.
This data arrives at server and is received by thread Th1 while the main the main thread of Server continues to listen on port 21.
My question is how does the further data sent by client C1 on the same connection which was made on port 21 automatically goes to the thread Th1 ? even though the main thread of server is listening on port 21 for new connections ?
multithreading tcp network-programming client-server
multithreading tcp network-programming client-server
asked Nov 10 at 12:37
Ahmed
5,1261568114
5,1261568114
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
up vote
0
down vote
You need to provide any package which gets send between client a server with a unique client id
. You need a distinguishable hand-shake packet.
When the server receives a hand-shake
packet, it starts a thread, gives it the client id from the packet, and continues listening to port 21.
Thread then sends whatever is need, say at port 22 to the client and starts listening on a conditional variable
.
When the server's main thread gets a data
packet at port 21, it publishes the id
and signals the conditional variable
. One of the waiting threads will recognize the id and will start working. Alternatively the main thread can created multiple queues and conditional vars, one per thread and wake only a single thread which related to the id. Meanwhile the server continues listening.
Do not forget to kill the thread either at a good-bye
packet or at a timeout
.
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
You need to provide any package which gets send between client a server with a unique client id
. You need a distinguishable hand-shake packet.
When the server receives a hand-shake
packet, it starts a thread, gives it the client id from the packet, and continues listening to port 21.
Thread then sends whatever is need, say at port 22 to the client and starts listening on a conditional variable
.
When the server's main thread gets a data
packet at port 21, it publishes the id
and signals the conditional variable
. One of the waiting threads will recognize the id and will start working. Alternatively the main thread can created multiple queues and conditional vars, one per thread and wake only a single thread which related to the id. Meanwhile the server continues listening.
Do not forget to kill the thread either at a good-bye
packet or at a timeout
.
add a comment |
up vote
0
down vote
You need to provide any package which gets send between client a server with a unique client id
. You need a distinguishable hand-shake packet.
When the server receives a hand-shake
packet, it starts a thread, gives it the client id from the packet, and continues listening to port 21.
Thread then sends whatever is need, say at port 22 to the client and starts listening on a conditional variable
.
When the server's main thread gets a data
packet at port 21, it publishes the id
and signals the conditional variable
. One of the waiting threads will recognize the id and will start working. Alternatively the main thread can created multiple queues and conditional vars, one per thread and wake only a single thread which related to the id. Meanwhile the server continues listening.
Do not forget to kill the thread either at a good-bye
packet or at a timeout
.
add a comment |
up vote
0
down vote
up vote
0
down vote
You need to provide any package which gets send between client a server with a unique client id
. You need a distinguishable hand-shake packet.
When the server receives a hand-shake
packet, it starts a thread, gives it the client id from the packet, and continues listening to port 21.
Thread then sends whatever is need, say at port 22 to the client and starts listening on a conditional variable
.
When the server's main thread gets a data
packet at port 21, it publishes the id
and signals the conditional variable
. One of the waiting threads will recognize the id and will start working. Alternatively the main thread can created multiple queues and conditional vars, one per thread and wake only a single thread which related to the id. Meanwhile the server continues listening.
Do not forget to kill the thread either at a good-bye
packet or at a timeout
.
You need to provide any package which gets send between client a server with a unique client id
. You need a distinguishable hand-shake packet.
When the server receives a hand-shake
packet, it starts a thread, gives it the client id from the packet, and continues listening to port 21.
Thread then sends whatever is need, say at port 22 to the client and starts listening on a conditional variable
.
When the server's main thread gets a data
packet at port 21, it publishes the id
and signals the conditional variable
. One of the waiting threads will recognize the id and will start working. Alternatively the main thread can created multiple queues and conditional vars, one per thread and wake only a single thread which related to the id. Meanwhile the server continues listening.
Do not forget to kill the thread either at a good-bye
packet or at a timeout
.
answered Nov 10 at 13:52
Serge
3,0762912
3,0762912
add a comment |
add a comment |
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53239023%2fhow-does-client-data-go-to-sub-thread-of-the-server-rather-than-original-listeni%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password