简体   繁体   中英

is it legal to create two socket connection to same port with two threads

In my multi-threaded application there may be more then one thread which are accessing a application to the same port with different socket. Is this programatically right as in my case when second thread create socket connection to the same port then first thread status shows as running but it does nothing. For example.

Let there are one Thread t1. It create a socket connection at port 2106 and start fetching data. Now it is fetching data and writing to the file system. In meanwhile another Thread t2 start. This t2 Thread create a socket connection to the same ip at same port 2106 and fetch data. Now in my case thread t2 fetches data but Thread t1 do nothing.

Could any body tell why this is?

Based on your text it is not illegal for 2 Threads to create and maintain a connection socket to a Server socket listening on a port.

This is what a Browser with tabs do, if you open for example facebook.com from 2 different tabs.

But as it turns out your Server seems like an Iterative connection server, which means you don't create a separate thread or process to handle each connection. But all modern web servers are concurrent connection servers, so if you create 2 different connections from 2 different threads, It will in turn handle by two different threads in the server side.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM