python scripting

Posted on 2014-07-13
Medium Priority
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
  • 2
LVL 20

Accepted Solution

simon3270 earned 1500 total points
ID: 40194245

    clientsocket = None

after the close.

Author Comment

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

Expert Comment

ID: 40194320
Yes, that would break it too!  :)

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: Swadhin
Introduction of Lists in Python: There are six built-in types of sequences. Lists and tuples are the most common one. In this article we will see how to use Lists in python and how we can utilize it while doing our own program. In general we can al…
If you haven’t already, I encourage you to read the first article (http://www.experts-exchange.com/articles/18680/An-Introduction-to-R-Programming-and-R-Studio.html) in my series to gain a basic foundation of R and R Studio.  You will also find the …
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.
Suggested Courses
Course of the Month16 days, 22 hours left to enroll

864 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