Link to home
Start Free TrialLog in
Avatar of Josh Ransom
Josh Ransom

asked on

python scripting

I am trying to get some server side code on python working just a quick and dirty approach to it. This is just a prototype mind you

Currently there are two types of clients 1 desktop 1 mobile
upon first connection the desktop will send DesktopClient1
mobile will send MobileClient2

Currently I am getting this as an error and I don't know how to solve it

return getattr(self._sock,name)(*args)
socket.error: [Errno 10048] Only one usage of each socket address (protocol/network address/port) is normally permitted

Open in new window


Below is the code

from socket import *
import thread, ssl
 
def handler(clientsocket, clientaddr):
    print "Accepted connection from: ", clientaddr
 
    while 1:
        data = clientsocket.recv(1024)
        i = 0 
        while (i <= 0):
            if data == "DesktopClient1":
                print data
                i = 1 + 1
                print 1
                print "Desktop Verified"
                clientsocket.send("Mobile Verified")
            elif data == "MobileClient2":
                print data
                i = 1 + 1
                print i
                print "Mobile Verified"
                clientsocket.send("Mobile Verified")
            else:
                break
            if not data:
                break
            else:
                print data
                msg = "You sent me: %s" % data
                clientsocket.send(msg)
    clientsocket.close()
 
if __name__ == "__main__":
 
    host = 'localhost'
    port = 55567
    buf = 1024
 
    addr = (host, port)
 
    serversocket = socket(AF_INET, SOCK_STREAM)
 
    serversocket.bind(addr)
 
    serversocket.listen(2)
 
    while 1:
        print "Server is listening for connections\n"
        
         
        clientsocket, clientaddr = serversocket.accept()
      
        thread.start_new_thread(handler, (clientsocket, clientaddr))
    serversocket.close()

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of simon3270
simon3270
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Josh Ransom
Josh Ransom

ASKER

ahh yes that will work also. I figured out apparently I had a running duplicate server in the background taking the same port :)
Yes, that would break it too!  :)