My application uses standard httpUrlConnection code to connect to a python code on apache http server.
All permissions of network access and internet are given. Previously I could not run this code as I was not using Asych (a different thread for network access) as I am working on Android 3.0 – Latest version. Now I am finished with this part.
No when I call the code below the response code is 200 which is all good:
#!/Python27/python
print "Content-type: text/html"
print
print "<html><head>"
print ""
print "</head><body>"
print "Hello."
print "</body></html>"
But when I use this code:
# Echo server program
import socket
HOST = '127.0.0.1'
PORT = 80
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.bind((HOST, PORT))
s.listen(1)
conn, addr = s.accept()
print 'Connected by', addr
while 1:
data = conn.recv(1024)
if not data: break
conn.sendall(data)
conn.close()
it gives 404 response code saying Exception FileNotFoundException.
More addition, yes the code above is for a server and this is a sample code from python socket library (so all the comments are not mine). I am writing a similar server that would give database connectivity and post/get features.
So, Just need to make sure what is the problem with the server code above?
Any hints are more than welcomed.
Thanks.
The above echo server code could not be connected as this was not a http server and so no response code was programmed and other information required from a http server are not implemented.
The code above it worked as it was ran from Apache so obviously that worked..
Thanks for commenting…