TCP server

A

assaf

i am try to create a server
what am i suppose to send to SocketServer.TCPServer
what is the client_address ("127.0.0.1:80" ?)
and BaseRequestHandler = ?

thanks
 
P

Pedro Werneck

A quick example for you:

###
import SocketServer


class EchoRequestHandler(SocketServer.BaseRequestHandler):
def setup(self):
print self.client_address, 'connected!'
self.request.send('hi ' + str(self.client_address) + '\n')

def handle(self):
while 1:
data = self.request.recv(1024)
self.request.send(data)
if data.strip() == 'bye':
return

def finish(self):
print self.client_address, 'disconnected!'
self.request.send('bye ' + str(self.client_address) + '\n')

#server host is a tuple ('host', port)
server = SocketServer.ThreadingTCPServer(('', 5000), EchoRequestHandler)
server.serve_forever()

###

Telnet to localhost 5000 and any data you sent will be echoed back to you... send 'bye' and the connection is closed
 
D

Dennis Lee Bieber

i am try to create a server
what am i suppose to send to SocketServer.TCPServer

I'll let others explain (I've not used it), but...
what is the client_address ("127.0.0.1:80" ?)

Localhost/loopback address, HTTP port. Planning to create a
web-server, perhaps?

--
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,216
Messages
2,571,120
Members
47,723
Latest member
Monika9748

Latest Threads

Top