2

I implemented an UDP socket server using python.The source code of the program shows below.

import socket
port_number = 116 #Checked it with various numbers
addressBar = list();
server_socket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)   
server_socket.bind(('localhost', port_number))              
print "UDPServer Waiting for client on port ",port_number
while True:
    dataFromClient, address = server_socket.recvfrom(256)
    if(address not in addressBar):
                addressBar.append(address)
    print dataFromClient
    if(len(addressBar)>1):
                for add in addressBar:
                        if(address != add ):
                                server_socket.sendto(dataFromClient, add)
    else:
        server_socket.sendto("No any connected devices", address)
    print addressBar

This server is working fine. But now I need to this, be an on-line server. I tried to host this in openShift (https://openshift.redhat.com/app/login?then=%2Fapp%2Fconsole%2Fapplications). but it was unsuccessful. I have 0 experience with python web application development so I need your kind help to get an idea bout "How to host this server and where to host ?"

Following source code shows the client side of the application.

import socket
print "Client"
client_socket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)    #This creates socket

while 1:
    data=raw_input("Message:")
    client_socket.sendto(data, ('localhost',117))
    print "Sending request"
    recv_data, addr = client_socket.recvfrom(256)
    print "Message<<Clent2>>",recv_data
client_socket.close()   
5
  • 2
    the first obvious thing, you need to check if UDP port that you use is opened on the hosting server. Most likely it's firewalled. Commented Jun 23, 2014 at 2:57
  • Opps thanks for the advice ill do it ... but when I trying to start the server it says "No module call socket". So I think this cannot be the problem. Open shift is supporting both python 2.7 and 3.0 here I used 2.7. Since "socket" is inbuilt module in python this cannot be happen. Commented Jun 23, 2014 at 3:01
  • Then it's a qs to their support about version that they use and why they don't have socket module, which should be in a standard lib in 2.7: /usr/lib/python2.7/socket.py - that's what I have on Linux. Commented Jun 23, 2014 at 3:12
  • Some times it may be a problem in the program. but some how it is not working is there any free host for python that I can try with Commented Jun 23, 2014 at 3:14
  • 1
    Try AWS' free tier - aws.amazon.com/free/… Commented Jun 23, 2014 at 3:17

1 Answer 1

3
server_socket.bind(('localhost', port_number))  

This is your problem - you need to bind to all interfaces, otherwise only connections from the same machine will be successful. Do this:

# bind to all interfaces
server_socket.bind(('0.0.0.0', port_number))  
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.