I'm developing android webRTC with coturn trun server. There is a problem in connection.
Case 1. no problem
Offer(LTE hotspot wifi connected device) -> <- Answer(WIFI connected device)
=> Always connected well
Case 2. problem in connection
Offer(WIFI connected device) -> <- Answer(LTE hotspot wifi connected device)
=> Always iceConnectionState failed.
my coturn server running command is
turnserver -X <publicip>/<privateip> --no-tls --no-dtls --min-port 50000 --max-port 60000 -r my.domain --no-auth --syslog -l stdout --relay-ip <privateip>
turn server is running aws amazon linux ec2 instance.
any idea?
I found a problem. when use --no-auth option, TCP connection always can't be made.
remove --no-auth option, and use authentication method.
I used lt-cred-mech option. and make user with turnadmin command.
Related
I built a flutter app which communicates with a web server that I wrote with flask. Everything works as intended without any errors if I use a virtual device. As soon as I try it in release mode on a physical device I get problems when it comes to the communication with the server
The only thing that I changed when using a physical device is the ip. I use 10.0.2.2 on the virtual device and my computers ip4 adress - that I get with ipconfig in windows 10 - on the physical device
Both devices are in the same network connected to the same router
Internet Permission is enabled in the AndroidManifest for all modes (Debug, Main, Profile)
I even disabled the firewall
The line that causes the issue is
await http.get(url).timeout(Duration(seconds: 15), onTimeout: () {
// Handle timeout
// This entire thing is in a try-catch block in an async function
});
In debug mode on the physical device when the HTTP get request is sent VSCode immediately says
Exception has occurred.
SocketException (SocketException: OS Error: Connection refused, errno = 111, address = 192.168.178.20, port = 43378)
First Question: Why Port 43378? Is that the port the HTTP request is sent to? Because when I run the flask app it says:
Running on http://127.0.0.1:5000/
Could that be the issue? I would have expected the exception to say the port is 5000 as declared in the URL. Or do I have to change something with how I set up the flask app? Currently it is the development server because I am still testing before I pay money and deploy
However I hope I didnt forget any important information. Any advice on what could be wrong or how to debug here is highly aprecciated
Pass an Uri object to http.get func. Uri classes let you specify the port as Documentation https://api.dart.dev/stable/2.12.0/dart-core/Uri-class.html
So this the first time I work with wifi-direct, I am trying to connect my android phone to a raspberry pi zero w over wifi-direct.
using this sample app on my android phone: https://github.com/ahmontero/wifi-direct-demo
I am able to get to the Connected state at the pi in the wpa_cli interface
and on the phone under the device name i see "connected" behind the progressDialog box that says "Connecting to 1e:67:58:4c:78:92" which should be dismissed after connecting but it isn't since WifiP2pManager.WIFI_P2P_CONNECTION_CHANGED_ACTION isn't being triggered after connecting.
my wpa_supplicant.conf:
ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
update_config=1
country=LB
ap_scan=1
device_name=raspberry
device_type=1-0050F204-1
driver_param=use_p2p_group_interface=1
p2p_go_intent=7
p2p_go_ht40=1
p2p_listen_reg_class=81
p2p_listen_channel=1
p2p_oper_reg_class=81
p2p_oper_channel=1
and have done the following:
on the Pi:
$sudo wpa_supplicant -B -dd -iwlan0 -Dnl80211 -c /etc/wpa_supplicant/wpa_supplicant.conf
$sudo wpa_cli p2p-dev-wlan0
p2p_group_add
OK
<3>P2P-GROUP-STARTED p2p-wlan0-0 GO ssid="DIRECT-VC" freq=2412 passphrase="JrLfUAJf" go_dev_addr=5a:d3:65:e8:fc:e7
wps_pbc
OK
<3>P2P-DEVICE-FOUND 1e:67:58:4c:78:92 p2p_dev_addr=1e:67:58:4c:78:92 pri_dev_type=10-0050F204-5 name='HUAWEI' config_methods=0x188 dev_capab=0x25 group_capab=0x0 wfd_dev_info=0x00101c440032 new=1
<3>P2P-PROV-DISC-PBC-REQ 1e:67:58:4c:78:92 p2p_dev_addr=1e:67:58:4c:78:92 pri_dev_type=10-0050F204-5 name='HUAWEI' config_methods=0x188 dev_capab=0x25 group_capab=0x0
On the Phone:
I run the wifi direct sample app from google
and i can see the device with its info and when i click on connect i get stuck at connecting progressDialog and cant get passed that point to connected mode eventhough i see "connected" under device name.
the app seems to work fine between two phones but with a pi
this line in WiFiDirectBroadcastReceiver.java doesn't get executed when a connection has been made with the pi
} else if (WifiP2pManager.WIFI_P2P_CONNECTION_CHANGED_ACTION.equals(action))
however, when connection is lost after a timeout for example it gets triggered!
my question is what am i doing wrong here, why isn't the WIFI_P2P_CONNECTION_CHANGED_ACTION being detected by the broadcast receiver?
Note: phone is running Android 7.1
compileSdkVersion 26
targetSdkVersion 26
edit:
As Ben has pointed out in his answer below that I need to have a DHCP server running on the GO device (PI in my case), so I went ahead and installed and configured DHCP service on the pi by following the first section at this link https://www.raspberrypi.org/documentation/configuration/wireless/access-point.md
but, I can no longer run sudo wpa_supplicant -B -dd -iwlan0 -Dnl80211 -c /etc/wpa_supplicant/wpa_supplicant.conf command successfully as it might be clashing with the dhcp conf? any idea how i can enable p2p while running DHCP?
Well,
So as a part of GDPR (EU) implementation and similar things.
From android 8 & onwards there will be a restriction on the way by which android devices receive broadcast on any event (ofcourse to hide few device specific infos/specs.)
Please have a look at this:
https://developer.android.com/guide/components/broadcasts
Cheers.
Your Raspberry Pi is in the GO role and needs to act as a DHCP server. An Android device in the Client role will not broadcast WIFI_P2P_CONNECTION_CHANGED_ACTION until it has received an IP address from the GO via DHCP.
See my answer here for further details.
I am trying to start a server on Android using QTcpServer with Qt 5.3.1 but the server does not start and I get "Unsupported Socket Operation". It works fine on Windows.
Code below:
void StartListening()
{
QHostAddress hostAddress;
hostAddress.setAddress(QString("localhost"));
hostAddress.toIPv4Address();
quint16 portNumber = 9878;
server->setMaxPendingConnections(1);
server->setProxy(QNetworkProxy::NoProxy);
if (server->listen(hostAddress, portNumber))
{
// Ok
}
else
{
Debug("Server did not start. " + server->errorString());
}
}
server->errorString() returns "Unsupported Socket Operation when it runs on Android
Isn't this supported by Qt Android or am I doing something wrong?
Thx
OK! I worked it out.
The problem is with this line:
hostAddress.setAddress(QString("localhost"));
If I replace "localhost" with "127.0.0.1", the server starts fine but no one outside the "device the server is running on" can connect to it. This means, let's say your network is using 192.168.1.xx and your Android device has the following IP address: 192.168.1.2. If you start the server with "127.0.0.1" on your Android device which has an IP address: "192.168.1.2" and then using your PC with an IP address 192.168.1.3 you do telnet 192.168.1.2 9878 it will fail to connect!
So then I decided to start the server by specifying the IP address of the Android device: 192.168.1.2
hostAddress.setAddress(QString("192.168.1.2"));
Voila! That works too! The server starts and I can connect from outside the device! For example if I do telnet 192.168.1.2 9878 from my PC while the server is started on Android, it connects! So all I need to do now is replace the hard coded IP address with the actual IP address of the device! I think QNetworkInterface::allInterfaces() or something like that will give me the ability to get the default IP address.
So just use the actual IP address of the network card rather than localhost or 127.0.0.1 and all should be Ok. All working now.
Is there an easy way, to see which ports are open on my Android device and a way to close the open ports?
Create a wifi hotspot on your phone
Connect your computer to the hotspot
use ipconfig or ifconfig to know the gateway IP adresse ( ie: your phone's IP adress )
Download nmap : http://nmap.org/
Use the nmap command : nmap -sS -Pn -p- your_phone_ip_adress
the open TCP ports will be shown as follow :
65531 closed ports PORT
STATE SERVICE
53/tcp open domain
8187/tcp open unknown
38647/tcp open unknown
42761/tcp open
unknown MAC Address: A4:9A:58:::** (Samsung Electronics Co.)
PS : For UDP ports use: nmap -sU -Pn -p- your_phone_ip_adress
You can determine the currently open ports by reading the textual /proc pseudo-files such as
/proc/net/tcp
/proc/net/udp
This is basically what a netstat command (where implemented) does - you may wish to find and examine the source of a simple netstat implementation (it should be possible to port such to java)
However, when running as an unprivileged app userid, you will only be able to close sockets belonging to your own process (or by roundabout means involving ptrace or process killing, other processes belonging to your userid). Also note that closing a socket does not necessarily make that port available for immediate re-use.
You can try different network commands through runtime and check the results
// netstat -lptu
// netstat -vat
Process su = Runtime.getRuntime().exec("netstat -vat ");
I am trying to make a way to telnet to an unrooted Droid. I have the INTERNET permission active, I have my device connected on the same network as my Mac OS X box via WiFi, and I am able to ping the port I opened.
In initial experiments, I got it to work on a rooted test device, but I had the socket handlers run on the UI Thread rather than a separate thread. Now that I have the network modules on a separate thread, I can't get ServerSocket.accept () to return. It works on Google's version of android (vanilla), but not on Samsung's or Sony-Ericsson's.
When I telnet to it, my attempt would time out, and logcat wouldn't print out any exceptions or errors.
Here is a link to a google-code repo of my code: Google-code Repository
I am running ServerScoket.accept () on a separate thread, and run the stream processors on another thread as well. Comments on my design (i.e. I should use Handlers or AsyncTasks) are extremely welcome. Right now, in order to Toast the messages received via telnet, I use a Handler with the looper being acquired via a Context.
The following is what I get when I run netstat -n on the adb shell on the non-working devices:
~$ adb shell netstat -n
Proto Recv-Q Send-Q Local Address Foreign Address State
tcp 0 0 127.0.0.1:7777 0.0.0.0:* LISTEN
tcp 0 0 127.0.0.1:7203 0.0.0.0:* LISTEN
tcp 0 0 127.0.0.1:47609 127.0.0.1:7777 ESTABLISHED
tcp 0 0 127.0.0.1:7777 127.0.0.1:47609 ESTABLISHED
tcp 0 0 127.0.0.1:47610 127.0.0.1:7777 ESTABLISHED
tcp 0 0 127.0.0.1:7777 127.0.0.1:47610 ESTABLISHED
The difference is that in the working devices, they list an IP with my port open in the state, LISTEN.
UPDATE: Having the <uses-permission android:name="INTERNET"/> set in my android_manifest, I tried changing the port number to 689. It didn't work; I got a BindException, saying that I may be lacking the INTERNET permission. So, I changed it to 1989, and I went back to everything working until accept (). I assume this is because I ran it on a non-root phone, and I don't have access to ports 1024 and below.
UPDATE: I ran a really similar program on my Mac, and it worked fine when I tried telnetting to my Mac using the IP address assigned to me. It didn't work when I tried telnetting from another Mac but it didn't seem to connect; the connection would timeout. It did work over an ad-hoc network, though. I still have yet to try it using the droid, but I will update this asap.
UPDATE: I managed to get the app working on 3 separate Droids running Vanilla (Android released by google). It worked on a Nexus, an Apanda A60 (my first device; adb has ceased to detect it for some reason.), and a custom-made, unbranded tablet. Still, because I already offered a pretty big bounty, I plan on seeing this through to the end.
As stated earlier, my app works with Vanilla versions of android, but not with modified versions. The three phones that failed to run it were all mid-range models; 2 Samsung GT-i5503s, and a Sony-Ericcson E16i.
It seems like you have a networking issue, rather than a code issue. I used your latest project and it is listening on the port, as expected.
I added this to TelnetServer.setupServerSocket() to confirm some information:
Log.i("TelnetServer", "ServerSocket Address: " + this.server.getLocalSocketAddress());
try {
Enumeration<NetworkInterface> en = NetworkInterface.getNetworkInterfaces();
while (en.hasMoreElements()) {
NetworkInterface intf = en.nextElement();
for (Enumeration<InetAddress> enumIpAddr = intf.getInetAddresses(); enumIpAddr.hasMoreElements(); ) {
InetAddress inetAddress = enumIpAddr.nextElement();
Log.i("TelnetServer", "Listen On: " + inetAddress.getHostAddress());
}
}
} catch (SocketException ex) {
Log.e("TelnetServer", ex.toString(), ex);
}
This will print all of the addresses your service is listening on (if it is listening on 0.0.0.0/0.0.0.0:xxx (printed after ServerSocket Address:)).
You should run emulator with the -tcpdump <file> option and also provide this. It will confirm any connection is being attempted. My hunch is that your client is not able to access the server, which is why the server is not receiving the connection - rather than an issue with the code.
Please provide the tcpdump file, your IP Address (of the client) and the logcat output (including the ServerSocket Address and Listen On statements) for further analysis.
See if netstat -n from the adb shell shows anything actually listening on the port you chose at the time when accept() is not returning.
Also realize that when not running as root, you can only bind unprivileged ports, of which the default telnet port is not an example. Does your code check that bind() was successful?
UPDATE:
Since the code works on a number of devices (where netstat -n would presumably list the socket) the failure to list it on the subject device should probably remain a focus. The Java ServerSocket methods depend on a socket factory which can be over-ridden to let you do distinct calls to socket(), bind(), and listen() specifying fuller details, so it may make sense to try your code that way. There's another case floating around where a device's attempt to support ipv6 seems to be causing someone similar problems, and at least on other java platforms creating the socket at a lower level to specify ipv4 seems like a promising answer.
I understand you have tried most of the things are you are just few steps from getting it right on two particular devices.
Just a thought, If not point to point, why not Use Muti-casting for service registration and discovery in local area networks.
This is the java implementation JmDNS
and this is its Android demo
EDIT : Rather I should say to check connectivity with that two devices.