SocketServer - what am I doing wrong?

j vickroy jim.vickroy at
Fri Dec 15 13:42:17 EST 2000


I'm having difficulty using the SocketServer module in Python 1.5.2 on a
Win NT 4.0 sp 6 platform.

Here are the files.

## begin file: ---------------------------

import SocketServer
#<??>import	socket

host	= '' # this machine
port	= 1984
address	= (host, port)

class Message_Handler (SocketServer .BaseRequestHandler):

	def handle (self):

		info = self .request .recv (1024) #<??> how does this work for a big
		print 'handler received', info
		self .request .send (info) # echo it back to sender
		print 'handler sent', info

if __name__ == '__main__':

	server = SocketServer .TCPServer (address, Message_Handler)
	server .serve_forever()

## end file: ---------------------------

## begin file: ---------------------------

from socket import *

server = '<the server>' # modify this for your machine !
port = 1984

connection = socket (AF_INET, SOCK_STREAM)
connection .connect ( (server, port) )

for i in range (1, 10):
	connection .send ('list python files')
	message = connection .recv (1024)
	print ' received ', `message`

connection .close()

## end file: ---------------------------

Here is a screen capture of the client side session:

 received  'list python files'
Traceback (innermost last):
  File "", line 16, in ?
    message = connection .recv (1024)
  File "<string>", line 1, in recv
socket.error: (10058, 'winsock error')

Here is a screen capture of the server side:

handler received list python files
handler sent list python files

What am I doing incorrectly?

Thanks for your time.

-- jv

More information about the Python-list mailing list