?
Solved

python scripting

Posted on 2014-07-13
3
Medium Priority
?
780 Views
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")
            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

0
Comment
Question by:Josh Ransom
  • 2
3 Comments
 
LVL 20

Accepted Solution

by:
simon3270 earned 1500 total points
ID: 40194245
Add

    clientsocket = None

after the close.
0
 

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 :)
0
 
LVL 20

Expert Comment

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

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