in Education by
In the next examlpe I have Socket server handled in the thread. In the handle function we create Thread and pass request and client_address. When we handle the request in run-method of the Thread it's only possible to receive data, but when I try to send somthing an Exception is raised ([Errno 9] Bad file descriptor) What's wrong? import SocketServer import threading class MyServerThread(threading.Thread): def __init__(self, channel, details): self.channel = channel self.details = details threading.Thread.__init__(self) def run(self): print 'Received connection:', self.details[0] self.channel.send('(Response)') print 'Received:', self.channel.recv(1024) self.channel.close() print 'Closed connection:', self.details[0] class MyThreadedSocketServerHandler(SocketServer.BaseRequestHandler): def handle(self): thread1 = MyServerThread(self.request, self.client_address) thread1.start() if __name__ == '__main__': server = SocketServer.TCPServer(('localhost', 8888), MyThreadedSocketServerHandler) server.serve_forever() #---Client to test--- import socket message = "(Request)" sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) try: sock.connect(('localhost', 8888)) sock.send(message) data = sock.recv(1024) print 'Sent: %s' % message print 'Received: %s' % data finally: sock.close() #Working example without "join" import socket import threading class ClientThread(threading.Thread): def __init__(self, channel, details): self.channel = channel self.details = details threading.Thread.__init__(self) def run(self): print 'Received connection:', self.details[0] self.channel.send('message') print self.channel.recv(1024) self.channel.close() print 'Closed connection:', self.details[0] server = socket.socket(socket.AF_INET, socket.SOCK_STREAM) server.bind(('', 8888)) server.listen(5) while True: channel, details = server.accept() ClientThread(channel, details).start() JavaScript questions and answers, JavaScript questions pdf, JavaScript question bank, JavaScript questions and answers pdf, mcq on JavaScript pdf, JavaScript questions and solutions, JavaScript mcq Test , Interview JavaScript questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)

1 Answer

0 votes
by
I think you are looking for ThreadingMixIn: from SocketServer import TCPServer, ThreadingMixIn class MyServerThread(ThreadingMixIn, TCPServer): pass

Related questions

0 votes
    In the next examlpe I have Socket server handled in the thread. In the handle function we create Thread ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 13, 2022 in Education by JackTerrance
0 votes
    In the next examlpe I have Socket server handled in the thread. In the handle function we create Thread ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 13, 2022 in Education by JackTerrance
0 votes
    Hey there Stack Overflow. I'm trying to build a testing script that should mix outputting changing ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 21, 2022 in Education by JackTerrance
0 votes
    I need to react in a main process to random events happening in a child process. I have implemented ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jul 27, 2022 in Education by JackTerrance
0 votes
    If I use socket.makefile and then close the file object as well as the underlying socket, then subsequent ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 23, 2022 in Education by JackTerrance
0 votes
    In __________, each external request is tagged with a unique identifier which is passed to all services involved ... . Distributed tracing C. Application logging D. Audit logging...
asked Jan 11, 2023 in Education by JackTerrance
0 votes
    In __________, each external request is tagged with unique identifier which is passed to all services involved in ... b)Audit logging (c)Application logging (d)Exception tracing...
asked Oct 21, 2020 in Technology by Editorial Staff
0 votes
    Which of the interface contains all the methods used for handling thread related operations in Java? (a) ... questions and answers pdf, java interview questions for beginners...
asked Oct 25, 2021 in Education by JackTerrance
0 votes
    What I'm trying to do here is get the headers of a given URL so I can determine the MIME type. ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 11, 2022 in Education by JackTerrance
0 votes
    I have this script: import threading, socket for x in range(800) send().start() class send( ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jun 5, 2022 in Education by JackTerrance
0 votes
    I am using Eclipse with Pydev and googleAppengine. I have python 2.7 installed. I am trying to run ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 19, 2022 in Education by JackTerrance
0 votes
    I am exploring Float Label pattern for web page using HTML and CSS. The code was referred from http: ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 27, 2022 in Education by JackTerrance
0 votes
    I have a FileCreator class that implements StreamResourceWriter interface and MainErrorHandler class that implements ... Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 14, 2022 in Education by JackTerrance
0 votes
    How should I handle /_ah/start and /_ah/stop requests? Right now they're just getting 404s. Also, ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 7, 2022 in Education by JackTerrance
0 votes
    I have a self hosted gitlab on ubuntu machine. I configure a linux container for it to run runner. ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 22, 2022 in Education by JackTerrance
...