tcp ip - TCP/IP back to back read and write taking too long -


i trying transfer messages using tcp/ip. found if 1 party acts sender , other party acts receiver, transfer fast. if 2 parties switch roles more often, becomes slow.

to specific, operation takes 6 ms:

**server:**  (int = 0; < 5000; i++){     read(connfd, s1, 128);       read(connfd, s2, 128); }  **client:**  (int = 0; < 5000; i++){     write(sockfd, s1, 128);      write(sockfd, s2, 128); } 

and operation takes 98 ms:

**server:**  (int = 0; < 5000; i++){     read(connfd, s1, 128);       write(connfd, s2, 128); }  **client:**  (int = 0; < 5000; i++){     write(sockfd, s1, 128);      read(sockfd, s2, 128); } 

is there way reduce delay?


Comments

Popular posts from this blog

c++ - OpenCV Error: Assertion failed <scn == 3 ::scn == 4> in unknown function, -

php - render data via PDO::FETCH_FUNC vs loop -

The canvas has been tainted by cross-origin data in chrome only -