Unable to connect android socket connection over Cellular network - android

I am working on Android chat project. I have managed to build chat application which can handle text, file exchange and audio call using TCP Socket and UDP Datagramsocket connection. Every thing is working fine on local network but when I try to use cellular data it fails.
I am not much more familiar with the networking background but if it work on my local network then it should work on cellular network as it is a part of big network with some securities. I need help to figure out where I am doing mistake and how can i manage to resolve them.
In my project I am using port 80,1234,50002,50001,50003,8555,8553,8080 to communicate between client and server on TCP and UDP. On my local network I have no security so all ports are open for me locally but on cellular network may be these ports are not open. For this issue, how can I find the open ports on cellular network? Or is there any other alternative to use socket connection over cellular network.
Thank you

Related

Can an Androip app on Chromebook create a socket TCP server, listen connections and connect to other socket server on LAN network?

I have an android app that creates a socket TCP server to listen connections from a windows app. And sometimes it connects to the socket server on windows app.
It works properly on android devices. It can also receive broadcast packets.
However, it does not work when I install on Chromebook.
It cannot listen any connection, receive any packets or connect to the server on windows app.
Could anyone help me explain why and guide me some solutions to fix?
Best regards.
I understood about network in Chromebook and found Network Service Discovery as the solution here https://developer.android.com/topic/arc
Check for networking requirements
Chromebooks run the entire Android OS in a container, similar to Docker or LXC. This means that Android will not have direct access to the system's LAN interface. Instead, IPv4 traffic will pass through an internal layer of network address translation (NAT), and IPv6 unicast traffic will be routed through an extra hop. Outbound unicast connections from an Android app to the internet should mostly work as-is; but in general, inbound connections are blocked. Multicast or broadcast packets from Android will not be forwarded to the LAN through the firewall.
As a special exception to the multicast restriction, Chrome OS runs a service that forwards mDNS traffic between Android and the LAN interface, so the standard Network Service Discovery APIs are the recommended way to discover other devices on the LAN segment. After finding a device on the LAN, an Android app can use standard TCP or UDP unicast sockets to communicate with it.
IPv4 connections originating from Android will use the Chrome OS host's IPv4 address. Internally, the Android app will see a private IPv4 address assigned to the network interface. IPv6 connections originating from Android will use a different address from the Chrome OS host, as the Android container will have a dedicated public IPv6 address.

React Native: How to always route socket packets through WiFi even if it does not have an internet connection?

I have a React Native application that uses TCP and UDP sockets by bridging to Java and Objective-C code. Unfortunately, I'm not at liberty to share the code.
The problem is that when I attempt to use these TCP/UDP modules when my phone is on a WiFi network that does not have an internet connection they do not work because the packets are being routed through mobile data. If I use my code when on a WiFi that does have an internet connection or when my mobile data is switched off, it works perfectly. This is true for both platforms Android/iOS.
How can I force all packets to go through the WiFi connection even if it does not have an internet connection?
Thanks.

Server on Android reachable from devices not on local network?

I have been trying to set up an app that allows communication between two devices, a server and a client. I have established the connection and can send messages between the two as long as they are connected to the same source of internet. When I connect the devices to two different sources, I am not able to establish a connection between the two. It works by entering the IP address of the server you want to connect to.
For example, if my server device is connected to my home Wi-Fi and my client device is connected to the same Wi-Fi router, communication works as supposed to. But, when I connect the server to Wi-Fi and my client to cellular data (or different Wi-Fi router), the client is not able to find the server.
From all the searching I've done, I found that it is because my server is bound to my local host. So my question is, How can I make my server reachable from anywhere regardless of what network you are connected to?
I used this tutorial to get my server running:
http://android-er.blogspot.com/2014/02/android-sercerclient-example-server.html
The very first comment is a question that asks why it only works on a local network and someone answered saying you have to set up port forwarding on your router. From what I understand, this will work only if the server device is always connected to the same router. This will not be the case for my app. The server will have a new IP address as the device changes networks. I want this IP address to always be reachable no matter what network the server is connected to.
You will need to create a relay server. This would be set up using a java application on the PC and it would manage virtual "rooms" that then relay the messages to the clients. The computer you run your relay server off of will need port forwarding but the clients will not. Much of the code from that tutorial could be applied to this concept.
See: How to create a java Server that accepts client connections and then build a relay connection for a client pair
If your server is behind a firewall, you will not be able to reach it unless that port is open on the firewall. The only way to avoid this is to have a non-firewalled server.

Receiving data through wifi connection

I'm trying to make the following work, and wonder if it is possible:
I want to send data from a hardware piece to an android device. Although the hardware only has an Ethernet connection available.
If I were to make an Ethernet connection from the hardware piece to a router, and then communicate from the router to the android device with WiFi, is there any way I could tell the android device, just receive data from the WiFi?
Using IP protocol will allow you to communicate over any IP network.
Easiest way to do that is using TCP sockets that uses Server/Client relation to communicate.
I'm guessing you are using a microcontroller (arduino?) if that is the case there are many IP labraries and examples you can look at.
after writing the server code on the hardware then you can easily use sockets to connect to it from android, here is an example on how to connect android client to TCP server.
TCP Client tutorial
Extra links:
TCP on Wikipedia no need to read the implimentation details just understand the concept.
Java All about Sockets Great overview of socket programming and should get you ready to write effective code on the android side.
LAN wikipedea article about LANs

Socket communication with android devices

Can i interact with a server(android device) from a client(android device) just to query a database located in the server using TCP sockets?
And Yes and No.
If your device is within wireless network and have own local IP. You can connect to it from client phone if it is in the same network just providing proper IP and Port.
If server phone is located in another wireless network, then Port have to be forwarder using router settings to the server port. Bear in mind that if you will reconnect to wireless network by phone, then IP will be automatically assigned by network infrastructure and it might be changed from previous.
If you want to connect to server phone when it is on 3G network (or similar non wifi), you wont have any specific IP, and it is not static, that way it will be almost impossible to create reliable network. It is more Peer-to-Peer model of network you are looking for.
It is much better if you use Server in the middle as Gateway, that way it will be reliable. The only thing is that you will have to host server and its processes with all traffic and so on.

Categories

Resources