Android client and server socket connection - android

Is it possible to make connection with server Mac Address using Socket or Do I need IP address of the server to setup the connection from client to server using Socket
socket = new Socket(serverAddr, SERVERPORT);
If I use IP address that change over the time so I don't want to use it. I want that remain same for the Android phone that seems Mac address to me.
Here both client and server is the Android Phone.

It sounds like you're trying to connect to the same device, even as it might be getting a new IP address?
MAC address is one way to do that. Per this blog post, you can read from /proc/net/arp and parse this information out, because Android is Linux-based. The MAC address-IP address mappings are stored in this file, and you can use the extracted IP address to do the Socket connect.
In general, you need an IP address to open a socket connection. Consider an analogy. Sending a packet over a socket is like sending a piece of mail to a street address. The IP address is the street address. If you don't know where your friend lives, you can't send her mail. If she moves, and doesn't tell you her new address, you can't send her more mail.

Related

sql server connection in android studio

android studio, how connect to sql server withpout a server ip sample http:\myhomepage:1433
i dont waht to connect use an ip sample:
111.111.1.111:1433
To connect to your localhost server, you should be connected to the same network (Phone and the Computer with the server), just open cmd and type ipconfig and get the ip address for the server. in your android connection string enter http://ipaddress/projectfolder
You can only connect using the domain name http://example.com for a hosted live website since mobile devices won't recognize your localhost

Getting "You don't have permission to access that port" error in Django

I want to run my Django API to my IP address which is 192.168.1.5:81 with port number but I am getting that You don't have permission to access that port.
I have done port forwarding in my router.
I am doing this because I want to get data in my Android application using retrofit.
i checked my available ports on my IP address then i ran code with the open port and solved this.
also i added my IP address inside ALLOWED_HOSTs in settings.py file

Server with dynamic IP

I am making an app that uses socket programming. Client side is programmed using android and server side using Java. The IP address of the server may change and the IP address has to be kept secure and private.
I do not want the users to install the app again and again when the IP of server changes.
You can use domain for your server . your domain is static and not change dynamically.
for example your domain is : yoursystem.com
now your server ip is : xxx.xxx.xxx.xxx
and tomarow your ip change to yyy.yyy.yyy.yyy
but your domain address is static and user can conect to your domain.
if your privacy is important you can improve your privacy by set token for your user and ...

Android get connection to sql server

I need to connect to local sql server, but when run code below,
con = DriverManager.getConnection("jdbc:jtds:sqlserver://10.0.3.2:8080/app", "test", "1234");
the logcat display warning message:
06-10 01:24:22.112 2676-2676/com.example.androidapp.helloandroid W/EGL_genymotion﹕ eglSurfaceAttrib not implemented
I dont know what does the warning message means?? I have tried to googled and they recommend use localhost/127.0.0.1/10.0.2.2/10.0.3.2/(local ip address) or remove port number, but it isn't working...
you can not use localHost there should be client server communication. Between a device and server.
So use an ip address remove localHost from url and if you are able to ping that ip from another machine then only we can access it from your android device.

How to send an image both side using WIFI Direct?

I am working on an app where ,i am able to send an image only one way,from client to groupowner.How can i send it in both ways?
I had done bi-directional data transfer in my project. In Wifi Direct group owner Ip is decided by OS itself which is known to both devices i.e Server as well as client. Client know the IP of server on which it has to send data, But server don't know the client IP.
For that you have to send client IP address to server and store that address in sharedPrefrences. So you should initiate transfer silently when connection made so that server store the client IP, for next transfer.
Socket client = serverSocket.accept();
String WiFiClientIp = client.getInetAddress().getHostAddress();
you can made a check while transfer i.e if IP don't match server Ip then send data to client IP.
For testing purpose when you send file from client to server, in AsyncTask doinbackground method you can get the IP address of client which is also decide by OS itself. Put that IP statically then you will be able to send file on client also.
I will share my code on github soon. I hope this info will help you.
Working Bi-Directional Data Transfer APK File-> https://play.google.com/store/apps/details?id=anuj.wifidirect&hl=en

Categories

Resources