python scripting

Posted on 2014-07-13
Last Modified: 2014-07-14
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")
            if not data:
                print data
                msg = "You sent me: %s" % data
if __name__ == "__main__":
    host = 'localhost'
    port = 55567
    buf = 1024
    addr = (host, port)
    serversocket = socket(AF_INET, SOCK_STREAM)
    while 1:
        print "Server is listening for connections\n"
        clientsocket, clientaddr = serversocket.accept()
        thread.start_new_thread(handler, (clientsocket, clientaddr))

Open in new window

Question by:Josh Ransom
    LVL 19

    Accepted Solution


        clientsocket = None

    after the close.

    Author Comment

    by:Josh Ransom
    ahh yes that will work also. I figured out apparently I had a running duplicate server in the background taking the same port :)
    LVL 19

    Expert Comment

    Yes, that would break it too!  :)

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Suggested Solutions

    Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
    When we want to run, execute or repeat a statement multiple times, a loop is necessary. This article covers the two types of loops in Python: the while loop and the for loop.
    In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…
    In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

    779 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    10 Experts available now in Live!

    Get 1:1 Help Now