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()