Skip to content
Advertisement

Socket Programming with Python server and Android client

I want to setup a socket interface. PC side runs a very simple socket server written in Python to test the connection:

JavaScript

An Android client application will connect to PC:

JavaScript

However, I cannot establish a connection between PC and Android device. Any idea to fix this?

Advertisement

Answer

As you haven’t detailed if you’re using either private or public IPs, it might be any of the following issues:

If you’re using private connections, it’s obvious it’s not a router-firewall related problem as you are under the same net, so there are only a few possibilities:

  • There’s nothing listening on that port on that IP on the server-side
  • There’s a local firewall on the server-side that is blocking that connection attempt
  • You are not using WIFI so you’re not under the same net.

You should make sure you can open that service some ther way, that would help you debugging where the culprit is. If you’ve already done this, I’d suggest using some debugging tool to trace TCP packets (I don’t know either what kind of operating system you use on the destination machine; if it’s some linux distribution, tcpdump might help; under Windows systems, WireShark might be useful).

If you’re using public IPs, sum up a router blocking firewall, which means that this port might be closed/filtered on the server side, just open it.

All that assuming you have the android.permission.INTERNET permission in your AndroidManifest.xml file.

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement