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

  • SEARCH
  • Home
  • 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 8878655
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T19:45:50+00:00 2026-06-14T19:45:50+00:00

I am trying to establish a communication pipe between a C executable and python

  • 0

I am trying to establish a communication pipe between a C executable and python script.
Below is the Python script, and the weird thing about this is the following. If I run
the python script as below, then the C executable NEVER sees any data on the socket.

However, if I uncomment the Reader class (ie., only writting to the socket is enabled)
then the C executeable ALWAYS receives the data on the socket. Has anyone an explanation why this is not working when the Reader and Writer thread are running simultaneously?

class Reader(Thread):
    def __init__(self):
        Thread.__init__(self)
        self.daemon = True
    def run(self):
        while True:
            s = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
            s.connect("/tmp/demo_socket")               
            nonce = s.recv(4)
            s.close

            if len(nonce) == 4:
                print("Result received \n")

class Writer(Thread):
    def __init__(self):
        Thread.__init__(self)
    def run(self):
        while True:
            payload = "Hello World"
            s = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
            s.connect("/tmp/demo_socket")           
            s.send(payload)
            s.close()

reader = Reader()
writer = Writer()

reader.start()
writer.start()


try:
    while True:
        sleep(10000)
except KeyboardInterrupt:
    print("Terminated")

EDIT:

As suggested I am trying to open the connection globally as below but that gives me two additional problems:

1) After sending data, only 4 bytes should be received on the Python end but it seems I am receiving an endless stream of data…

2) Where can I close this globally opened stream?

s = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
s.connect("/tmp/demo_socket")  

class Reader(Thread):
    def __init__(self):
        Thread.__init__(self)
        self.daemon = True
    def run(self):
        while True:        
            nonce = s.recv(4)

            if len(nonce) == 4:
                print("Result received \n")

class Writer(Thread):
    def __init__(self):
        Thread.__init__(self)
    def run(self):
        while True:
            payload = "Hello World"         
            s.send(payload)

reader = Reader()
writer = Writer()

reader.start()
writer.start()


try:
    while True:
        sleep(10000)
except KeyboardInterrupt:
    print("Terminated")
  • 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-06-14T19:45:52+00:00Added an answer on June 14, 2026 at 7:45 pm

    1) After sending data, only 4 bytes should be received on the Python end but it seems I am receiving an endless stream of data…

    Your sender keeps on sending, and if the data you receive are replies to that, the server keeps on answering.

    2) Where can I close this globally opened stream?

    After you don’t need it any longer… Do you have a stop condition or something like that?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to create a two-way communication channel between two programs (one in Python
I am trying to establish a basic .NET Remoting communication between 2x 64bit windows
I am trying to establish USB communication as host. I am following the examples
I'm trying to establish a relationship between two models in Rails but I am
I am trying to establish upper / lower bound in my stored procedure below
all I am trying to establish peer to peer (UDP) communication via firefox extension.
I'm trying to establish a new sort criteria, in this case by name. I'm
I'm trying to setup a RFCOMM client-server communication system between my PC and my
I am trying to establish connection between ZABBIX SERVER which has been installed on
I'm trying to establish a communication with an ONVIF camera, and I'm getting some

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.