PC SOFT

FORUMS PROFESSIONNELS
WINDEVWEBDEV et WINDEV Mobile

Accueil → WINDEV Mobile 24 → Conexao Internet
Conexao Internet
Débuté par adrianoboller, 18 nov. 2014 14:05 - 5 réponses
Membre enregistré
2 958 messages
Popularité : +89 (91 votes)
Posté le 18 novembre 2014 - 14:05
Procedure ConexaoInternet()

GloConexaoInternet = 0

ok is boolean = False

PosicaoOK is int = 0

Httpurl, HttpRetorno is string

IpSaladaFruta01 is string = Morango_01 +"."+ Abacaxi_02 +"."+ Limao_03 +"."+ Melancia_04 +":"+ Laranja_05

Httpurl = "http://"+IpSaladaFruta01

HTTPTimeOut(GloHTTPTimeOut)

IF HTTPRequest(Httpurl) = True AND Httpurl <> "" THEN

HttpRetorno = HTTPGetResult(httpHeader)

PosicaoOK = PositionOccurrence(HttpRetorno,"Connection",firstRank,IgnoreCase)
IF PosicaoOK = 0 THEN
PosicaoOK = PositionOccurrence(Upper(HttpRetorno),"200",firstRank,IgnoreCase)
IF PosicaoOK = 0 THEN
PosicaoOK = PositionOccurrence(Upper(HttpRetorno),"OK",firstRank,IgnoreCase)
END
END

IF Httpurl <> "" AND PosicaoOK > 0 AND HttpRetorno <> "" THEN
GloConexaoInternet = 1
ok = True
ELSE
GloConexaoInternet = 0
ok = False
END

ELSE
GloConexaoInternet = 0
ok = False
END

RESULT(ok)
Membre enregistré
2 958 messages
Popularité : +89 (91 votes)
Posté le 18 novembre 2014 - 14:06
Procedure ConnectInternet(LOCAL RedesSN, LOCAL Webservice, LOCAL DebugSN)

//Exemplo:
x is int = TimeSys()
Conexao is string = "ServidorRadioTaxi" + x

IF SocketConnect(Conexao,8085,"177.124.60.220",60000) = False //60 segundos de tentativa

IF DebugSN = "S"
Error("ServidorRadioTaxi Real OFF-LINE" + ErrorInfo(errMessage))
END

GloConexaoInternet = 0
PosicaoOK is int = 0
gsNetworkType is string
Httpurl, HttpRetorno is string

IF Webservice = ""
Httpurl = "http://www.google.com.br"
ELSE
Httpurl = Webservice
END

HTTPTimeOut(GloHTTPTimeOut)

IF HTTPRequest(Httpurl) = True AND Httpurl <> "" THEN

HttpRetorno = HTTPGetResult(httpHeader)
IF DebugSN = "S" THEN
Info(Httpurl,HttpRetorno)
END

IF Webservice = "" THEN

PosicaoOK = PositionOccurrence(Upper(HttpRetorno),"OK",firstRank,IgnoreCase)
IF PosicaoOK = 0 THEN
PosicaoOK = PositionOccurrence(Upper(HttpRetorno),"200",firstRank,IgnoreCase)
IF PosicaoOK = 0 THEN
PosicaoOK = PositionOccurrence(Upper(HttpRetorno),"GOOGLE",firstRank,IgnoreCase)
END
END

ELSE
PosicaoOK = PositionOccurrence(HttpRetorno,"Connection",firstRank,IgnoreCase)
IF PosicaoOK = 0 THEN
PosicaoOK = PositionOccurrence(Upper(HttpRetorno),"200",firstRank,IgnoreCase)
IF PosicaoOK = 0 THEN
PosicaoOK = PositionOccurrence(Upper(HttpRetorno),"OK",firstRank,IgnoreCase)
END
END
END

IF DebugSN = "S" THEN
Info(PosicaoOK, Httpurl, HttpRetorno)
END

IF Httpurl <> "" AND PosicaoOK > 0 AND HttpRetorno <> "" THEN
GloConexaoInternet = 1
IF DebugSN = "S" THEN
NextTitle("Atenção")
Info("Com internet...")
END
ELSE
GloConexaoInternet = 0
IF DebugSN = "S" THEN
NextTitle("Atenção")
Info("Sem conexão...")
END
END

ELSE
GloConexaoInternet = 0
END

//New Area - Target Code - Android and iOS
//aix
//Tipo de internet
IF RedesSN = "S"
SWITCH MobileNetworkConnectionInfo(networkType)
CASE network2G
gsNetworkType = "2G"
CASE network3G
gsNetworkType = "3G"
CASE network4G
gsNetworkType = "4G"
OTHER CASE
gsNetworkType = "Wifi"
END
IF DebugSN = "S"
Info(gsNetworkType)
END
END

//New Area - Target Code - Android and iOS

IF GloConexaoInternet = 1 THEN
IF DebugSN = "S" THEN
NextTitle("Atenção")
Info("Dispositivo móvel com conexão: " + gsNetworkType + " - Situação On-Line")
END
ELSE
IF DebugSN = "S" THEN
NextTitle("Atenção")
Popup(GloMsgSemInternet,"L")
END
END

ELSE
IF DebugSN = "S"
Info("ServidorRadioTaxi Real On-Line!")
END
GloConexaoInternet = 1
END


RESULT(GloConexaoInternet)
Posté le 21 novembre 2014 - 15:33
Adriano;

Many many thanks for this code example! This have saved me many hours of research and testing!

Bob R.
Membre enregistré
2 958 messages
Popularité : +89 (91 votes)
Posté le 22 novembre 2014 - 12:53
I need your help to ask for a review in httptimeout command WINDEV Mobile that works on iphone and android project exactly the time set is not obeyed. If you do this please ask for the free support, helps me a lot ... So can you give me a hearing!
Membre enregistré
2 958 messages
Popularité : +89 (91 votes)
Posté le 24 novembre 2014 - 12:07
Procedure ConexaoInternet(LOCAL Debug)

//info("Verifica conexao com a internet")

gloConexaoInternet = 0
PosicaoGoogle is int = 0
gsNetworkType is string
Httpurl is string = "http://www.google.com.br"

IF HTTPRequest(Httpurl) = True AND Httpurl <> "" THEN

Httpurl = HTTPGetResult()
IF Debug = 1 THEN
Info(Httpurl)
END

PosicaoGoogle = PositionOccurrence(Httpurl,"google",firstRank,IgnoreCase)
IF Debug = 1 THEN
Info(PosicaoGoogle)
END

IF Httpurl <> "" AND PosicaoGoogle > 0 THEN
gloConexaoInternet = 1
IF Debug = 1 THEN
Info("Dispositivo móvel com conexão: " + gsNetworkType + " - Situação On-Line")
END
ELSE
gloConexaoInternet = 0
Info("Dispositivo móvel sem conexão - Situação Off-line")
END

END

Httpurl = ""

RESULT(gloConexaoInternet)
Membre enregistré
2 958 messages
Popularité : +89 (91 votes)
Posté le 24 novembre 2014 - 12:23
Procedure XMLConnect(LOCAL LinkUrl, LOCAL Tipo)

// Load the RSS

Xconnect is boolean = False

Stream is XMLDocument

IF Tipo = "Url"
Stream = XMLOpen(LinkUrl,fromURL)
ELSE IF Tipo = "Arquivo"
Stream = XMLOpen(LinkUrl,fromFile)
ELSE IF Tipo = "String"
Stream = XMLOpen(LinkUrl,fromString)
END

IF ErrorOccurred=True THEN
Error("Verifique a conexão com a internet!...")
Xconnect = False
ELSE
Xconnect = True
END

RESULT(Xconnect)