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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T13:45:17+00:00 2026-06-06T13:45:17+00:00

I am trying to implement a sort of reverse terminal: start server.py on some

  • 0

I am trying to implement a sort of reverse terminal:
start server.py on some computer foo.

On some other computer run nc foo 2000 and you are connected to a bash shell on foo.

I am using the following server code:

import socket,os,threading,select,subprocess                                                                                             

class mysocket(socket.socket):

    def __init__(self,*arg, **kw):
        super(mysocket,self).__init__(*arg, **kw)
        self.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
        self.setblocking(0)


    def read(self):
        return self.recv(2048)

    def write(self,data):
        self.send(data)

    def accept(self):
        conn,addr = super(mysocket,self).accept()
        return mysocket(_sock=conn),addr

socket.socket = mysocket

import SocketServer

class RequestHandler(SocketServer.BaseRequestHandler):

    def handle(self):
        subprocess.call(['bash','-i'],env=os.environ,stdin=self.request,stdout=self.request,stderr=self.request)

class ForkedTCPServer(SocketServer.ForkingMixIn, SocketServer.TCPServer):
    pass

if __name__ == '__main__':

    address = ('0.0.0.0', 2000) # let the kernel give us a port
    server = ForkedTCPServer(address, RequestHandler)

    server.serve_forever()

This works great if you only do one connection at a time.

However when I open a second connection, the nc program sits waiting, and my python process has the message:

[1]+  Stopped                 python server.py

If I type %1 to bring the process to the foreground, then the second nc screen starts working and I have two remote bash shells.

My question is why does the python process get stopped, and how can I stop it from happening?

As far as I can tell nothing is blocking, because once I resurrect the process everything works perfectly!

Thanks much.

  • 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-06T13:45:18+00:00Added an answer on June 6, 2026 at 1:45 pm

    I figured it out. The problem was with calling bash, as other things would work.

    Eventually on a whim I tried calling bash with the script command and it worked as expected.

    Here is some final code for anyone who wants it:

    import socket,os,threading,subprocess                                                                                                    
    
    class mysocket(socket.socket):
    
        def __init__(self,*arg, **kw):
            super(mysocket,self).__init__(*arg, **kw)
            self.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
    
        def read(self):
            return self.recv(2048)
    
        def write(self,data):
            self.send(data)
    
        def accept(self):
            conn,addr = super(mysocket,self).accept()
            return mysocket(_sock=conn),addr
    
    socket.socket = mysocket
    
    import SocketServer
    
    class RequestHandler(SocketServer.BaseRequestHandler):
    
        def handle(self):
            subprocess.call('script -q -f -c "bash -i" /dev/null',shell=True,env=os.environ,stdin=self.request,stdout=self.request,stderr=self.request)
    
    class ThreadedTCPServer(SocketServer.ThreadingMixIn, SocketServer.TCPServer):
        pass
    
    if __name__ == '__main__':
        address = ('0.0.0.0', 2000)
        server = ThreadedTCPServer(address, RequestHandler)
        server.serve_forever()
    

    Note that this does not work on windows because of python’s lack of support for using sockets as files on that platform. However it works perfectly on cygwin.
    Just install python and util-linux (for the script command) from cygwin’s setup.exe.

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

Sidebar

Related Questions

I'm trying to implement some sort of 'just-for-me' game engine and the problem's plot
I'm trying to implement some STL-style sorting algorithms. The prototype for std::sort looks something
I'm trying to implement some sort of API on tornado and I have such
Basically I'm trying to implement some sort of poor man's Aspect Oriented Programming in
We're trying to implement some sort of Chess game and we have defined an
I am trying to implement some sort of MVC in Java. Actually it's more
I am trying to implement dijkstra's algorithm for path finding and need some sort
I was trying to implement a sort of shared cache between two or more
I'm trying to implement drag/drop/sort between 2 list elements: <ul id=first> <li>item 1</li> <li>item
im trying to implement some behaviors when a mapview element scrolls... by coding a

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.