I have a simple socket class: MySocketLib.py ..
import socket
class socklib():
def create_tcp_serversocket(self,port):
serversocket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
serversocket.bind((socket.gethostname(), port))
serversocket.listen(5)
return serversocket
def send_msg(self, sock, msg, msglen):
... blah blah ...
def recv_msg(self, sock, msglen):
... blah blah ....
My main file is Server.py as follows:
import MySocketLib
class serverclass():
def __init__(self,port):
self.servsock = 0
self.port = port
def run(self):
self.servsock = self.create_tcp_serversocket(self.port)
(clientsock, address) = self.servsock.accept() # ERROR: 'SELF' not defined
... blah blah ...
#############################
### Main startup code
if __name__ == '__main__':
server = serverclass(2000) # server is on port 2000
server.run()
I keep getting the below error:
File "D:\CodeLearn\Server.py", line 14, in serverclass
(clientsock, address) = self.servsock.accept()
NameError: name 'self' is not defined
I can't seem to get a handle on the concept of "self". Some times, it seems to be needed and sometimes not. Why would i need to define 'self' here when it is a python keyword?