Hi,
I have never been into sockets, so I decided to dive in.
With some help from devshed, I managed to make a server as shown below. But I cant get it receive data from client.
Please correct me :)
ERROR:
socket.error: (10057, 'Socket is not connected')
import socket as skt
class MServer:
def __init__(self):
print "Welcome to Hosanna Chat server: \n Server started...."
# Make a socket
def makesock(self, stype = skt.AF_INET, smode = skt.SOCK_STREAM):
newsock = skt.socket(stype, smode)
return newsock
# Bind socket to address
def bindsock(self, sock, name="localhost", address_port=80):
sock.bind((name, address_port))
#Listen to connections
def listensock(self, max_conn, sock):
sock.listen(max_conn)
print "Listening...."
#Aceept the connection
def acceptsock(self, sock):
clientsock, address = sock.accept()
print "Accepted connection from Client socket Address %s, port %s" %address
#Get data from client
def getdata(self, buff, sock):
data = sock.recv(buff)
return data
sv1 = MServer()
s1 = sv1.makesock()
sv1.bindsock(s1)
sv1.listensock(2, s1)
while True:
sv1.acceptsock(s1)
data = sv1.getdata(1024, s1)
print data