I build a socket server with python's SocketServer
module:
import SocketServer
class MyTCPHandler(SocketServer.BaseRequestHandler):
def handle(self):
# self.request is the TCP socket connected to the client
self.data = self.request.recv(1024).strip()
print "{} wrote:".format(self.client_address[0])
print self.data
# just send back the same data, but upper-cased
self.request.sendall(self.data.upper())
if __name__ == "__main__":
HOST, PORT = "localhost", 9999
server = SocketServer.TCPServer((HOST, PORT), MyTCPHandler)
server.serve_forever()
I can access server with http://localhost:9999/
in my computer, but I cannot access with my phone(my phone is in local area network because I connect the wifi from computer.) with IP:http://192.168.123.1:9999
.
I have used python -m SimpleHTTPServer 9999
to test my network, I can access my computer with my phone.