By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
444,199 Members | 1,125 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 444,199 IT Pros & Developers. It's quick & easy.

TCP server

P: n/a
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

Jul 18 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a

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


On 24 Jan 2005 06:25:18 -0800
"assaf" <as****@ixi.com> wrote:
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

--
http://mail.python.org/mailman/listinfo/python-list

Jul 18 '05 #2

P: n/a
On 24 Jan 2005 06:25:18 -0800, "assaf" <as****@ixi.com> declaimed the
following in comp.lang.python:
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?

-- ================================================== ============ <
wl*****@ix.netcom.com | Wulfraed Dennis Lee Bieber KD6MOG <
wu******@dm.net | Bestiaria Support Staff <
================================================== ============ <
Home Page: <http://www.dm.net/~wulfraed/> <
Overflow Page: <http://wlfraed.home.netcom.com/> <

Jul 18 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.