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
Cannot create socket
by Jeremy Aiyadurai other posts by this author
Apr 30 2002 10:17PM messages near this date
view in the new Beta List Site
Re: Cannot create socket | Re: was (no subject) + new thread
Hi there,

i get the following error when i try to recieve from a socket

Traceback (most recent call last):
  File "D:\backup\pythonstuff\projects\hyperd\webserver.py", line 51, in ?
    server.start()               # '()' again
  File "D:\backup\pythonstuff\projects\hyperd\webserver.py", line 20, in start
    self.handle(ss)             # Whenever calling a method from your
  File "D:\backup\pythonstuff\projects\hyperd\webserver.py", line 40, in
handle
    self.getparse(ss)
  File "D:\backup\pythonstuff\projects\hyperd\webserver.py", line 43, in
getpars
e
    response = ss.recv(1024)
  File "<string> ", line 1, in recv
socket.error: (10057, 'Socket is not connected')




Your help is much appreciated,

Jer


###########################################

#!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(1)
		print "\nListening..."
		self.handle(ss)             # Whenever calling a method from your
                              # own class, make sure it's self.xxxxx
	
	def checkForConn(self, ss):  # Don't forget those "self" parameters
		client = 0
		try:
			client = ss.accept()
			# Make sure those '()' are in there
		except:
			return client
		return client
	
	def handle(self, ss):        # "self" parameters
		Done = 0                    # Need to assign Done before referencing it
	  	while not Done:
	  #		if self.checkForConn(ss):  Again, self.xxxx
	  #	  	print "hit\n"
		  	client = self.checkForConn(ss)
		  	if client:
		  		print client
		  		self.getparse(ss)
		  		
	def getparse(self,ss):
		response = ss.recv(1024)
		print response
				
				


if __name__ == "__main__":
	server = webserver(80,'/')  # Make sure port is passed as integer
	server.start()               # '()' again


_______________________________________________
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