Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3407472
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T05:45:19+00:00 2026-05-18T05:45:19+00:00

I have 2 processes running in different machines which are communicating via TCP sockets.

  • 0

I have 2 processes running in different machines which are communicating via TCP sockets.
Both processes have code that acts both as a server and as a client.
I.e. ProcessA has opened a server socket that binds at portX and ProcessB has opened a server socket bind at portY.
ProcessA opens a client socket to connect with ProcessB and start sending messages as a client
and receiving responses (over the same tcp connection of course).
ProcessB once it receives a message and processes it, it sends the response, but also could send a message over the second tcp connection, i.e. where ProcessB has opened a client socket to portX of ProcessA.
So the flow of messages are over 2 different tcp connections.
My problem is the following: Taking as granted that this “architecture” can not change and must stay as is:
I have the problem that intermittently, the messages send from ProcessB to ProcessA over the tcp connection that ProcessB has opened the client socket, arrive at processA before the messages send as responses from ProcessB to ProcessA over the tcp connection that ProcessA has connected as a client socket.
I.e. Both flows occur

(1)  
ProcessA ---->(msg)----> ProcessB(PortY)  (TCP1)
ProcessB does processing   
ProcessB(portY)--->(response)----->ProcessA (TCP1)  
ProcessB--->(msg)----->ProcessA(portX)  (TCP2)

(2)  
ProcessA ---->(msg)----> ProcessB(PortY)  (TCP1)
ProcessB does processing   
ProcessB--->(msg)----->ProcessA(portX)  (TCP2)
ProcessB(portY)--->(response)----->ProcessA  (TCP1)

EDIT (after ejp request)
How can I enforce/make sure that ProcessB does not send a msg over the connection that ProcessB has a client socket open to server portX of ProcessA, before the message send as a reply from server portY of ProcessB arrives at processA? I.e. to have only flow (1) of the above.
Note that processB is multithreaded and the processing is non-trivial.

UPDATE:
May be it is my misconception, but when a process sends data over socket, and control is returned to application, this does not mean that the receiving side has received the data.
So if a process sends data over 2 sockets, is there a race condition by OS?

UPDATE2
After answer I got from Vijay Mathew:
If I did a locking as suggested, is there a guarantee that OS (i.e. IP layer) will send the data in order? I.e. finish one transmission, then send the next? Or I would they be multiplexed and have same issue?

Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T05:45:19+00:00Added an answer on May 18, 2026 at 5:45 am

    The obvious solution is:

    LockObject lock;
    
    ProcessA ---->(msg)----> ProcessB(PortY)
    
    // Processing the request and sending its response 
    // makes a single transaction.
    synchronized (lock) {
        ProcessB does processing   
        ProcessB(portY)--->(response)----->ProcessA (TCP1)
    }
    
    // While the processing code holds the lock, B is not
    // allowed to send a request to A.
    synchronized (lock) {
        ProcessB--->(msg)----->ProcessA(portX)  (TCP2)
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have several server processes that once in a while respond to messages from
I have a existing project (non-web), with multiple components/programs running on different machines. The
I have two running processes in Windows, and each process has a pipe to
I have a long running process in VB6 that I want to finish before
I have an importer process which is running as a windows service (debug mode
I have two unrelated processes that use .NET assemblies as plugins. However, either process
A single Biztalk Server can have multiple Host processes. Is it possible to create
We have a build machine running in our development department, which we've set up
I have to set environment variables on different windows machines, but I don't want
Background We have worker processes that read jobs from a table in SqlServer then

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.