Android Question How to connect directly to a VB6 computer application. Smartphone has no own ip

Michael Müller Anywhere

Member
Licensed User
Longtime User
Hi,
I want to connect my smartphone with my VB6-Windows-Desktop-Application to send a status from the smartphone to the pc.
With ServerSocket and AsyncStreams there are no proplems when I use the WLAN.

Without a WLAN it doesn't work because my smartphone has no own ip.

A other (indirect) way is the librarie "HttpJob" to send a post-request to a php5-Script on a internet-web-server which includs "socket_create" and "socket_connect" and which can directly connect to my windows-desktop-app. This works.

But is there a way to connect the smartphone directly with my desktop-app to send a string from a smartphonewithout an own ip-adress ?

Regards
Michael
 

Michael Müller Anywhere

Member
Licensed User
Longtime User
Thank you, I have hoped so. You offer so many socket libraries.

Which is the best library / way to connect directly to my computer ?

The pc is reachable with a hostname (I use an dns-service).
When I have to use an ip I must send the ip before to the smartphone.
For this way I have already implemented the GCM.
It was easy to learn with B4A - thank you for this !
 
Upvote 0

Beja

Expert
Licensed User
Longtime User
How far is your computer from your phone?
If within 10 meters then you can use Bluetooth and no need to connect through the internet.
 
Upvote 0

Michael Müller Anywhere

Member
Licensed User
Longtime User
That can be up to 30 kilometer. My windows VB6 application supports winsocket. There Iam listening on port 4750.
My provider does'nt support an own ip on the smartphne so I can't connect when I am not in a WLAN.
I have to send a status-string and gps-location from the smartphone to the computer.
 
Upvote 0

Michael Müller Anywhere

Member
Licensed User
Longtime User
No, that uses too long time (minutes / hours). The users are firedepartments, police, emergency and so on.
The status which is send must be immediately on the computer (in my windows dispatcher-software).
My android app should be an additional tool/help for dispatchers.
 
Upvote 0

coslad

Well-Known Member
Licensed User
Longtime User
Hi

you can call the android device with GCM framework , an the device can reply to the desktop app with a tcp socket .
 
Upvote 0

Michael Müller Anywhere

Member
Licensed User
Longtime User
Yes, I already use the GCM Framework to send messages (orders) from the desktop to the android. That works fine.
Since many years I work with sockets (winsock). I developed many server and client applications with the VB6 IDE.

Last week I found B4A by change in the Internet and I began to work with it.
The directly TCP/IP direction from the smartphone to the desktop-windows-computer is not possible.
That its what I tried to explane with my posts.
A smartphone has no own ip-adress. In a WLAN yes it has and it works. I have already tried it. The smartphone gets his IP-adress from the WLAN-router.

But when I am in the forrest and not in a WLAN area, my Smartphone has no IP-adress. In this moment
you can not connect directly with socket to any winsocket server.
That is the reason why I can not use B4A-socked libraries.
The reason why smartphones has no own IP is that the most providers dont offers that or you have to buy for this option.
The most users who should use my app later doesn't have this option.

The only solution I found until now is to send a string via the B4A "HttpJob" library to a php5-script on a webserver.
This php5 script can redirect my messages via "socket_create" and "socket_connect" and "socket_send" to my
desktop appication. This works.

But I wish to find a solution to connect direct from B4A to Visual-Basic6 to send a Message from B4A.
 
Upvote 0

sorex

Expert
Licensed User
Longtime User
why don't you use a dynamic dns service to give your server behind a flexible ID a dns name that updates when the IP changes?

and for the phone.. use 3G/4G or a wifi service that covers most of the country.
 
Upvote 0

Michael Müller Anywhere

Member
Licensed User
Longtime User
To reach my desktop-computer is not the problem. But it does't accept the ConnectionRequest because my smartphone has no IP-adress.
A wifi-net is not available in a forrest, mountains or other outlying places where my app will be used.
 
Upvote 0

coslad

Well-Known Member
Licensed User
Longtime User
Hi,

You said that you yet use the Gcm framework with vb6. Can you share same sample code?

You can write a server app with b4j without any php page
 
Upvote 0

Beja

Expert
Licensed User
Longtime User
Well, if it is that critical and life support, then even the intetnet is not reliable and you should use long-range RF radio.
Search for long-range data xceiver radio. I know one with more than 30 miles and serial interface.
 
Upvote 0

Michael Müller Anywhere

Member
Licensed User
Longtime User
@coslad: here is the kernel code snipped to send GCM with VB6. After the last (every) line you can handle the answer of the requests.
Your GoogleAppID and your SENDER_ID should be declared as "const" before.
As parameter you can give the "Msg" and the "device_id" from the smartphone.

Is it possible to write a desktop-computer server app that can receive messages from a smartphone that has no own IP ?


CODE:

URL = "android.googleapis.com"
URL_Objekt = "gcm/send"

hInternetOpen = InternetOpen(App.EXEName, INTERNET_OPEN_TYPE_PRECONFIG, vbNullString, vbNullString, 0)
hInternetConnect = InternetConnect(hInternetOpen, URL, INTERNET_DEFAULT_HTTP_PORT, vbNullString, "HTTP/1.1", INTERNET_SERVICE_HTTP, 0, 0)
hHttpOpenRequest = HttpOpenRequest(hInternetConnect, "POST", URL_Objekt, "HTTP/1.1", vbNullString, 0, INTERNET_FLAG_RELOAD, 0)

'add 3 Headers
sHeader = "Authorization: Key=" & GoogleAppID & vbCrLf
bRet = HttpAddRequestHeaders(hHttpOpenRequest, sHeader, Len(sHeader), HTTP_ADDREQ_FLAG_REPLACE Or HTTP_ADDREQ_FLAG_ADD)

sHeader = "Content-Type: application/x-www-form-urlencoded;charset=ISO 8859-1" & vbcrlf
bRet = HttpAddRequestHeaders(hHttpOpenRequest, sHeader, Len(sHeader), HTTP_ADDREQ_FLAG_REPLACE Or HTTP_ADDREQ_FLAG_ADD)

sHeader = "Sender: Key=" & SENDER_ID & vbCrLf
bRet = HttpAddRequestHeaders(hHttpOpenRequest, sHeader, Len(sHeader), HTTP_ADDREQ_FLAG_REPLACE Or HTTP_ADDREQ_FLAG_ADD)

sPostData = "collapse_key=score_update&time_to_live=108" & _
"&delay_while_idle=1" & _
"&data.message=" & Msg & _
"&data.time=" & mNow & _
"&registration_id=" & device_id

dwTimeOut = 10000 '10 Sekunden
bRet = InternetSetOption(hHttpOpenRequest, INTERNET_OPTION_CONNECT_TIMEOUT, dwTimeOut, 4)
bRet = InternetSetOption(hHttpOpenRequest, INTERNET_OPTION_RECEIVE_TIMEOUT, dwTimeOut, 4)
bRet = InternetSetOption(hHttpOpenRequest, INTERNET_OPTION_SEND_TIMEOUT, dwTimeOut, 4)
bRet = HttpSendRequest(hHttpOpenRequest, vbNullString, 0, sPostData, Len(sPostData))


@Beja
Decoding Radio-Data is one of many more featrures of my Windows-Application. To send an alarm-message to a spartphone and send back the status or locations should only be an additional way to inform the people.
 
Upvote 0

coslad

Well-Known Member
Licensed User
Longtime User
Thanks for the sample code.
What is not clear is whether the device is connected to the internet or not, if it is connected to the internet even though with a shared IP address, there is no problem communicating with the server.
 
Upvote 0

M.LAZ

Active Member
Licensed User
Longtime User
Hi Michael, i'm working on project use the same idea , but just in WLAN,
i want to connect directly using TCP/IP from the smartphone to the desktop-windows-computer using IP-adress from the WLAN-router.
Could u help me in a small project in B4A and VB6 how to connect and send/receive data between the devices. and any tips...
any information will be appreciated and donated.
 
Upvote 0

Michael Müller Anywhere

Member
Licensed User
Longtime User
Hello,
the only way I found for the direction smartphone --> desktop-computer is to send a message to a php-script on my server:

B4A-Code:

Dim job1 As HttpJob
Msg="mymsg=hello test"
job1.PostString("http://www.myserver.com/myscript.php5", Msg)


The script can look like this:


$msg = $_REQUEST["mymsg"];
$port=12345;
$address="hostnameofmydesktopcomputer.com";
$socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
$result = socket_connect($socket, $address, $port);
socket_write($socket, $msg, strlen($msg));


Your desktop-aplication can listen on every port that you are setting in the script
Don't forget to set a portforwarding in the router to the IP of your computer.

With this solution you don't need a special provider or an expensive contract.

The way from the desktop to the smartphone you can resolve with GCM
 
Upvote 0
Top