4

So I'm in the process of learning to make an android app, and will require a server to get information from. I have created a simple server that just listens on port 65431 for connections and once a connection is established, just writes out a line of text.

The problem is, I can test the server from an external network and it all works fine, however, when I test it from my local network, it doesn't.

What I mean by local network:

  1. Server on Macbook IP 192.168.5.111 (not DHCP, statically assigned by router)
  2. Have a static IP from ISP
  3. Trying to test server from phone connected to home Wifi IP 192.168.5.101
  4. When testing localhost, it works, but not to static IP

When I test from my phone, there is no connection made. Any thoughts?

SlightlyCultured
  • 163
  • 1
  • 1
  • 6

1 Answers1

2

Your server would be bound to the static IP what you've mentioned. Set the server to run on IP 0.0.0.0 and all done.

Test the access with following command on server:

telnet <ip-address> <port>

James Jithin
  • 8,925
  • 3
  • 34
  • 50
  • I don't quite understand why binding to 0.0.0.0 would fix this problem. Would this be a safe thing to do for a server? – SlightlyCultured Sep 11 '15 at 02:17
  • Binding to 0.0.0.0 just means that bind to all network interfaces/ip configured for the current machine. MySQL server defaults to 0.0.0.0 ip binding as mentioned in this document: https://dev.mysql.com/doc/refman/5.1/en/server-options.html#option_mysqld_bind-address – James Jithin Sep 11 '15 at 03:24
  • Oh ok. So how do I do this bind? I tried: ServerSocket server = new ServerSocket (65431, 10, InetAddress.getByName("0.0.0.0")); This didn't work though. – SlightlyCultured Sep 11 '15 at 05:39
  • Try the way mentioned in this link: https://dzone.com/articles/java-testing-socket-listening Refer to the end part: ServerSocket serverSocket = new ServerSocket(port, 50, InetAddress.getByAddress(new byte[] {0x00,0x00,0x00,0x00})); – James Jithin Sep 11 '15 at 05:45
  • Doesn't seem to be working either. I wonder if the issue lies with the connection failing at the router. I am essentially trying to make a TCP connection with myself. – SlightlyCultured Sep 11 '15 at 08:19
  • Do you have a firewall blocking the packets? – James Jithin Sep 11 '15 at 08:21
  • Not sure. How would I check this? Sorry for being such a pain with the mundane questions. – SlightlyCultured Sep 12 '15 at 11:55
  • @SlightlyCultured, which operating system? – James Jithin Sep 12 '15 at 16:18
  • Macbook running yosemite. – SlightlyCultured Sep 14 '15 at 00:22
  • You may try disabling the firewall and starting the server. Refer:https://support.apple.com/kb/PH18635 If issue persists, please get the output of command mentioned in http://stackoverflow.com/questions/4421633/who-is-listening-on-a-given-tcp-port-on-mac-os-x/23600649 – James Jithin Sep 14 '15 at 02:05