cannot connect server when is in android phone - android

I'm working on a google cardboard project (Unity that will run on android phone)
I created a server in the Unity program that opens like this:
TcpListener listener = new TcpListener(IPAddress.Any, port);
listener.Start();
TcpListener client = listener.AcceptTcpClient();
Everything on backgroundworkers and nice things.
Then I connect from another piece of code running in a PC (WPF C# code). If Im running both programs in the PC I can connect flawlessly but when I compile for android and move the server to the phone, I cannot connect to it from the PC
When I try to perform:
host = Dns.GetHostEntry("192.168.1.8");
I get: Unknown host
The IP is correct (I made the server in the phone show it on screen, and I can ping to it) I think the problem is more related to the thing being in a different machine than to the fat that it is compiled for android but nevertheless.. here you have the full story.
Any help ?

Not sure what it was becauseI moved to UDP messages, and now it works.

Related

Call localhost API within react native ( android device : connected through local)

Have created a simple GET API using node.js and trying to consume it within my expo-react native project using axios/fetch.
The GET API is called whenever user clicks on submit button.
Submit -> http://localhost:port/api
However, when I am trying to test the feature on my android device by connecting the device through datacable and selecting "local" connect type in expo, the API call always falls under exception.
When I tried to log the exception, the exception is printed empty.
I double checked the API and it works fine when tested through postman.
I tried replacing localhost url with my-Ip (http://IP:port/api) and also with 127.0.0.1/127.0.2.2 (http://127.0.0.1:port/api , http://127.0.2.2:port/api) , but nothing seems to make the API call a success.
When I replaced the localhost URL with Facebook's network sample API, the application worked just fine. So, there is no issue with the API calling method.
Also, tried adding the port to windows inbound firewall request but that didn't work too.
Can someone help me out with this ?
You must call the API from your local IP address. To get your local IP, just do the following:
If you are on Ubuntu 16.04:
ifconfig | grep 192
If you are on Ubuntu 18.04:
ip -c a | grep 192
Your local IP address will probably be something like 192.168.0.XXX.
yes, i also had this problem until use my Local IP (example: http://192.168.1.55:port) instead 127.0.0.1
please see this answer
Good day,
This is working
I use my machine's IP the Ethernet adapter Ethernet 2: IPV4 Address
And allow my port on firewall both Inbound and outbound rules

Listing Computers in a Network

I have been using the following code to list computers on my Home Network.
if (path.equals("smb://")) {
domains = (new SmbFile(path)).listFiles();
}
When I had 2 Windows 10 PCs on my network, this worked fine.
However, since I added a 3rd Windows 10 PC, it throws an exception : "jcifs.smb.SmbAuthException: Logon failure: unknown user name or bad password.".
If I turn the new computer off, the code works again.
ES File Explorer can access the new Computer from the same Android device.
My question is in 2 parts.
a) Can anyone tell me what I need to do to get the new PC to appear in the list?
or
b) Can I get listfiles() to ignore the PC? I see you can add an SMBFileNameFilter to the call but can't find much information on what this does and how to use it.

How can I transfer information from an Android app to a Ni myRio embedded hardware device

I am trying to transfer instructions from an Android app to a Ni myRio embedded hardware device.
I can't seem to find any documentation.
Try starting with this:
Android
Run your Android application in the IDE's built-in Android Mobile Device Emulator.
Have it stream 'Hello World' via UDP to some port on localhost (say, 1234)
LabVIEW RIO
Run your RIO application against the LabVIEW FPGA Emulator (right-click your FPGA target in project explorer and select 'run on -> emulator')
Have it listen to 1234 on localhost, and print the output to a simple String Buffer that displays on the VI's front panel*1
Both of these have readily searchable tutorials*2, and remove HW from the equation, so you should be able to complete them successfully, and then iterate past to a final solution (WiFi?). If you get it working on real HW, consider posting a (brief) followup-answer to your question here.
-Justin
*1: Don't do this front-panel debug-hack in the deployed fpga code!
*2: Check NI's Example Finder for the LabVIEW FPGA UDP tutorials.

Can't connect to local web server from Android device

I've connected my Android phone to my laptop using Connectify.
I have a cherrypy web server running on 192.168.210.1:8080:
import cherrypy
class HelloWorld:
def index(self):
return "Hello world!"
index.exposed = True
cherrypy.quickstart(HelloWorld())
It works on my laptop, but when I try to put 192.168.1.8080 in my Android, there's no response and it keeps waiting indefinitely. I tried pinging to the IP from my phone, and it works, showing replies.
I also tried turning Windows Firewall off - it instanantly results in the message "Oops! Google Chrome could not connect to 192.168.210.1:8080". If I start it again, it's back to the previous state.
Please help.
You need to bind the socket on which the server is listen to '0.0.0.0', by default is bound to localhost, to do that just change the quickstart call, with this config:
config = {'global':
{'server.socket_host': '0.0.0.0'}
}
quickstart(HelloWorld(), config=config)

How to make socket connection from Android Emulator to another pc which is on the same lan

I am very new to Android. Our lan is working in class C IP (192.168.1.x series).
I need to establish socket connection between android emulator(Server) and java eclipse (eclipse-java-juno-SR1) which is acting like a client. As I got a information from "http://developer.android.com" website every Android emulator having 10.0.2.15 (Class A IP) by default. But our LAN is working in Class C.
"PC-1" which is using for Android Emulator is having 192.168.1.50 IP, and
the another one "PC-2" which is using for Eclipse-Java is having 192.168.1.55.
This is the setup which I have.
My work is, When I send a string command (through socket) from Android emulator(runing on PC-1) to Java program(runing on PC-2) then that Java program should send continuous jpg photo to Android emulator through socket.
I tried lot but when I try to work with sockets installed apk application is closing by this error: "Unfortunately, Activity name> is closing"
Please help me out in this...
Thanks in advance :)
Does your Application have the
<uses-permission android:name="android.permission.INTERNET"></uses-permission>
in your Manifest - File ?
You can either insert the above line into the manifest xml,
or you can go to "permissions" add "uses permission" and then add the "Internet" one.
My Emulator has no problems opening a Webview to the internet with this permission,
and I can even access my router in my network through the browser in the emulator, which is on some 192.168... address.
Kind Regards and a Happy New Year,
karlheinz

Categories

Resources