Android Question WIFI terminal communication

mare1980k1

Member
Licensed User
Longtime User
I would like to make wifi terminal for communication between phone and independent device that is not on internet. I have the IP and the port of the device and I managed to make an application to connect to it.

My question is how to send and receive simple text?
Thanks in advance :)
 

mare1980k1

Member
Licensed User
Longtime User
Thank you for your response.
I looked up at this example, but I found a bunch of code that I didn't need and that is linked to some other code.

Please help me just to get through the first step.

I want to send text to wifi that I am connected to.
I tried:
B4X:
Sub Process_Globals
   Private server As HttpServer
   Public port As Int = 2460
   Public MsgText As String
End Sub

Sub Service_Create
   server.Initialize("Server")
   server.Start(port)
End Sub

Sub btnConnect_Click
msgtext=lbltext.text
Dim sendmsg as ServletResponse
sendmsg.SendString(MsgText)
End Sub


I am looking for the most simple way to send text to a wifi device I am already connected. Please help. Thank you :)
 
Upvote 0

spairo

Member
Licensed User
I am developing android application in which there is a communication part between an OBD device and android device.
I'm planning to use ELM327 OBDII protocols for communication over WiFi network.
ATZ, ATPPxx, ATDI commands must be send to ELM327 Wifi device.
Through the SSID I get a connection to the Wifi network.
I can not set any IP address for the phone to connect to ELM327 WiFi.
In each case it gets the message " is Connected failed: EHOSTUNREACH (no route to host)".
How to set the client, server to be able to send commands from the phone to the ELM327 Wifi device.
log:
*** Service (starter) Create ***
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
** Activity (main) Pause, UserClosed = true **
** Activity (main) Create, isFirst = false **
** Activity (main) Resume **
Trying to connect to: 192.169.0.200
Failed to connect: (ErrnoException) android.system.ErrnoException: isConnected failed: EHOSTUNREACH (No route to host)
Trying to connect to: 192.169.0.201
Failed to connect: (ErrnoException) android.system.ErrnoException: isConnected failed: EHOSTUNREACH
or
Trying to connect to: 192.168.0.200
Trying to connect to: 192.168.0.200
Trying to connect to: 192.168.0.200
starter$ResumableSub_ConnectToServerresume (java line: 235)
java.net.SocketException: Socket is closed
at java.net.PlainSocketImpl.checkNotClosed(PlainSocketImpl.java:116)
at java.net.PlainSocketImpl.getInputStream(PlainSocketImpl.java:213)
at java.net.Socket.getInputStream(Socket.java:365)
at anywheresoftware.b4a.objects.SocketWrapper.getInputStream(SocketWrapper.java:220)
at b4a.SerializatorROB.starter$ResumableSub_ConnectToServer.resume(starter.java:235)
at anywheresoftware.b4a.BA.checkAndRunWaitForEvent(BA.java:240)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:180)
at anywheresoftware.b4a.BA$2.run(BA.java:360)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:158)
at android.app.ActivityThread.main(ActivityThread.java:7224)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)
 

Attachments

  • B4X-serializer.zip
    9.5 KB · Views: 216
  • 1008.jpg
    1008.jpg
    26.7 KB · Views: 207
  • 1009.jpg
    1009.jpg
    33.6 KB · Views: 230
  • 1010.jpg
    1010.jpg
    33.6 KB · Views: 312
Upvote 0
Top