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 6864827
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T02:57:42+00:00 2026-05-27T02:57:42+00:00

I’ve been working on this for 2 days and still I do not manage

  • 0

I’ve been working on this for 2 days and still I do not manage to get it to work properly.

I wanted to write an application that uses 2 sockets with a medium in the middle

This medium is this script that should read from socketA and write to SocketB and read from SocketB and write to SocketA.

However it seems I can not nail it.

My script when running accepts connections, but it will not allow me to input something on the telnet screen.

I am using 2 shared lists between the sockets to pass data.

    #!/usr/bin/env python
    import sys
    import arduinoReadThread
    import arduinoWriteThread
    import socket
    import thread



    bolt = 0
    socketArray=list()
    HOST =""
    HOST2=""
    PORT1 =50115
    PORT2 =50125



    s1=socket.socket(socket.AF_INET, socket.SOCK_STREAM ) #create an INET, STREAMing socket
    s1.bind((HOST,PORT1)) #bind to that port
    s1.listen(2) #listen for user input and accept 1 connection at a time.
    socketArray.append(s1)
    s2=socket.socket(socket.AF_INET, socket.SOCK_STREAM ) #create an INET, STREAMing socket
    s2.bind((HOST2,PORT2)) #bind to that port
    s2.listen(2) #listen for user input and accept 1 connection at a time.
    socketArray.append(s2)
    print "sockets set up"

    s1ToWriteList = list()


    s2ToWriteList = list()


    def socketFunctionWrite1():
            while(bolt == 0):
                client, address = s1.accept()

                print "Writing connections"
                if len(s1ToWriteList) > 0:
                    client.send(s1ToWriteList.pop(0))


    def socketFunctionRead1():
            while(bolt == 0):
                client2, address = s2.accept()

                f = client2.recv(1024)

                print "reading connection"
                s1ToWriteList.append(f)
                print len(s1ToWriteList)

    def socketFunctionWrite2():
            while(bolt == 0):
                client2, address = s2.accept()
                print "Writing connections"
                if len(s2ToWriteList) > 0:
                    client2.send(s2ToWriteList.pop(0))



    def socketFunctionRead2():
            while(bolt == 0):
                client, address = s1.accept()
                f = client.recv(1024)
            print "reading connection"
            s2ToWriteList.append(f)
            print len(s2ToWriteList)




def shutDown():
        test = raw_input("Quit ?")
        if(test =="y"):
            bolt = 1
        else:
            shutDown()

def spreadSockets():


        thread.start_new_thread(socketFunctionRead1,())
        print "launch 1"
        thread.start_new_thread(socketFunctionRead2,())
        print "launch 2"
        thread.start_new_thread(socketFunctionWrite1,())
        print "launch 3"
        thread.start_new_thread(socketFunctionWrite2,())

        print "launch 4"




spreadSockets()
while(True):
        pass
  • 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-27T02:57:43+00:00Added an answer on May 27, 2026 at 2:57 am

    Used your exact code and it worked for me. I think what you might be doing wrong is telnet’ing to the wrong IP. Dont use ‘localhost’ or 127.0.0.1, you need to use the actual (internal) IP of your box.

    If on linux, you can see if with ifconfig -a, or ipconfig /all on windows.

    Running your code exactly, no modification (except for removing the 2 unknown imports at the top):

    Launched script:

    [ 15:01 jon@hozbox.com ~/SO/python ]$ ./sock.py
    sockets set up
    launch 1
    launch 2
    launch 3
    launch 4
    Writing connections
    Writing connections
    ^CTraceback (most recent call last):
      File "./sock.py", line 93, in <module>
        time.sleep(1)
    KeyboardInterrupt
    

    Then telnet’d:

    [ 15:01 jon@hozbox.com ~ ]$ telnet 10.10.1.11 50115
    Trying 10.10.1.11...
    Connected to 10.10.1.11.
    Escape character is '^]'.
    Hello, World!
    Hello 2
    ^]
    telnet> quit
    Connection closed.
    [ 15:02 jon@hozbox.com ~ ]$ telnet 10.10.1.11 50125
    Trying 10.10.1.11...
    Connected to 10.10.1.11.
    Escape character is '^]'.
    Hello 50125!
    Hi!
    ^]
    telnet> quit
    Connection closed.
    [ 15:02 jon@hozbox.com ~ ]$
    

    My internal interface config (inet addr:10.10.1.11):

    [ 15:07 jon@hozbox.com ~/SO/python ]$ ifconfig eth0
    eth0      Link encap:Ethernet  HWaddr **:**:**:**:**:**
              inet addr:10.10.1.11  Bcast:10.10.1.255  Mask:255.255.255.0
              ...
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I need a function that will clean a strings' special characters. I do NOT
I'm working with an upstream system that sometimes sends me text destined for HTML/XML
I have a jquery bug and I've been looking for hours now, I can't
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
For some reason, after submitting a string like this Jack’s Spindle from a text
this is what i have right now Drawing an RSS feed into the php,
I've got a string that has curly quotes in it. I'd like to replace

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.