SocketServer - what am I doing wrong?

j vickroy jim.vickroy at noaa.gov
Fri Dec 15 19:42:17 CET 2000


Hello,

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: new_socket_server.py ---------------------------

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
file
		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: new_socket_server.py ---------------------------


## begin file: my_socket_client.py ---------------------------

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: my_socket_client.py ---------------------------



Here is a screen capture of the client side session:

D:\python\trials>python my_socket_client.py
 received  'list python files'
Traceback (innermost last):
  File "my_socket_client.py", 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