How to connect to Wifi

gilbertdurand

Member
Licensed User
Longtime User
Hello,

I need your help.

I have to connect to a specific wifi server.
For that, Basic 4 android must do :

turn on the wifi if not
connect the phone to the network with these parameters
an SSID
a Password
and a static IP ex: 192.168.1.11
a host and remote port

After that datas are exchanged between phone and the server

How can I do that ?

Thank's for your help
 

gilbertdurand

Member
Licensed User
Longtime User
ABWifi is not the good solution

ABWifi is only for getting informations from wifi not for setting information.

Network should be better but don't give for example the possibility to connect to a server with fixed IP.

So is there another solution ?
 
Upvote 0

mc73

Well-Known Member
Licensed User
Longtime User
You can try this.
What do you mean when referring to 'the possibility to connect to a server with fixed IP'?
Sockets are always opened using a hostName or IP plus a port.
 
Upvote 0

gilbertdurand

Member
Licensed User
Longtime User
connect to wifi

I saw Joehill librairy it can solve my problem to enable wifi but I'm not sure this librairy can help me to connect a device to a server with a specific IP.

I explain.

I have a server like this :
SSID : WIFISERVE
IP of the server : 192.168.1.20
Port 2000
Host IP 192.168.1.10
Host Port 2000

I want the phone to connect to WIFISERVE with IP 192.168.1.10 through the port 2000

I want to send data from the phone to the server by using IP 192.168.1.20:2000
I want to send data from the server to phone by using IP 192.168.1.10:2000

It seems I cannot with Joehill librairy be able to choose the IP 192.168.1.10 for the phone connected to the server
 
Upvote 0

mc73

Well-Known Member
Licensed User
Longtime User
You should use the host IP, if I understand correctly your problem.

Example:
B4X:
clientSocket.Initialize ("clientSocket")
clientSocket.Connect (hostIP ,hostPort,20000)
When the connection is established, you can exchange data using Asynchronous streams, for example.
 
Upvote 0

Stulish

Active Member
Licensed User
Longtime User
can you not just use the standard network lib, set up the phone to aromatically connect to the WiFi network and then use 2 sockets ( i only show one below):

B4X:
dim client as socket
client.connect("192.168.1.11",2000,20000)

Or am i being simple, not understanding your requirements?
 
Upvote 0

gilbertdurand

Member
Licensed User
Longtime User
How to force an IP adress when client associate with server

My problem is to force the IP adress when the phone associate with the server. For that, there is the static IP mode.
I examine the JhWifi librairie and saw some things quite interesting
as for example :

Wifi_Use_Static_IP
Wifi_Static_Netmask
Wifi_Static_IP
Wifi_Static_Gateway

Perhaps we can precise these parameters before an association, so when the client associate with the server these parameters are kept instead of parameters given by the server. What do you thing about this ? I will make a trial
 
Upvote 0

sorex

Expert
Licensed User
Longtime User
My problem is to force the IP adress when the phone associate with the server. For that, there is the static IP mode.

Why don't you just put the mac address of your phone/tablet in the DHCP server with the .10 IP registered to it?

Also in most cases an application requests data and will get a response back during the request (via http), there's no need to have the server send something to your IP.

and if it must you could send your device's hostname or current ip in the first (or all) request(s) to the server and save if somewhere. if you hit a dhcp release the server will refresh your ip if you send a next request.
 
Upvote 0

suciwulans

Active Member
Licensed User
Longtime User
how connect to wifi

what libraries i must use if i want to connect wifi? i tried use ABWifi and Jhwifi but can't connect to wifi. please help me/
 
Upvote 0
Top