ASPN ActiveState Programmer Network
ActiveState
/ Home / Perl / PHP / Python / Tcl / XSLT /
/ Safari / My ASPN /
Cookbooks | Documentation | Mailing Lists | Modules | News Feeds | Products | User Groups


Recent Messages
List Archives
About the List
List Leaders
Subscription Options

View Subscriptions
Help

View by Topic
ActiveState
.NET Framework
Open Source
Perl
PHP
Python
Tcl
Web Services
XML & XSLT

View by Category
Database
General
SOAP
System Administration
Tools
User Interfaces
Web Programming
XML Programming


MyASPN >> Mail Archive >> activepython
activepython
Re: Cannot create socket
by Matt Whiteley other posts by this author
May 1 2002 3:32PM messages near this date
view in the new Beta List Site
Re: Python device driver | Cannot create socket
Jer,

The client object contains two item, one being the connection object and the 
other the remote address. It's the connection object you want to receive 
data from.

The code below should work. I stuck a close for the socket in too.

###########################################
#!python

from socket import *

class webserver:

	def __init__(self,port,wwwroot):
		self.PORT = port
		self.WWWROOT = wwwroot

	def start(self):
		print "Starting server..."
		ss = socket(AF_INET,SOCK_STREAM)
		ss.bind(("127.0.0.1",self.PORT))
		print "Server Bound"
		ss.setblocking(1)
		ss.listen(100)
		print "\nListening..."
		self.handle(ss)


	def checkForConn(self, ss):
		client = 0
		try:
			client = ss.accept()
		except:
			return 0
		return client

	def handle(self, ss):
		Done = 0

		while not Done:
			client = self.checkForConn(ss)
			if client[0]:
				print "Client data : ", client[0], client[1]
				self.getparse(client)

	def getparse(self,client):
		connectionObj = client[0]
		response = connectionObj.recv(10240)
		print response

		#connectionObj.send(EnterReturnDataHere)

		self.closeConnection(connectionObj)

	def closeConnection(self, connectionObj):
		connectionObj.close()

if __name__ == "__main__":
	server = webserver(80,'/')
	server.start()

_________________________________________________________________
Chat with friends online, try MSN Messenger: http://messenger.msn.com

_______________________________________________
ActivePython mailing list
ActivePython@[...].com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
Other options: http://listserv.ActiveState.com/mailman/listinfo/ActivePython

Privacy Policy | Email Opt-out | Feedback | Syndication
© ActiveState Software Inc. All rights reserved