Android Question tcp client response

Yannick Proulx

Member
Licensed User
Hi guys,
I'm currently doing some test with the exemple FileClient (B4A/B4J) found on this forum. This exemple allow use to connect to a tcp server( B4J) and send stuff to this server then receive a reply from the server letting us know that the server received our stuff correctly.
the exemple come with a B4J server and the B4A client.
everything work fine with this setup.

I'm trying to create a socket in my .net app (actually a mqtt server) in order to make it work the same as the B4j server .
I'm able to receive message but i'm not able to reply to the B4A client and I think it's the way I reply to my client that is incorrect.

what do I have to reply to client in order to trigger this sub ( which is working in B4J)

B4X:
Sub JobDone(j As HttpJob)
    If j.Success Then
      
        ToastMessageShow("Success: " & j.GetString, False)
        Log("Success: " & j.GetString)
    Else
        ToastMessageShow("Error: " & j.ErrorMessage, True)
        Log("Error: " & j.ErrorMessage)
    End If
    j.Release
End Sub


Thanks for your help
Yannick
 
Last edited:

Yannick Proulx

Member
Licensed User
sorry for the misunderstanding,

I'm actually working with a mqtt server but I would like to convert this existing .net server to use the TCP Protocole instead of mqtt.

i'm actually able to send data to that server through TCP and the server can read it
My problem is when my server send data back to B4A client nothing happen and after a while the client write connection timed out as no reply reach it.
I'm wondering how should I format my reply string in .net in order to trigger the jobDone sub in B4A client.

also i know that my client is still connected to the server socket because when stop the server I immediatly see on client that the connection reset.

the reason I wanna switch from MQTT to TCP is the ability to send files over internet to my client. For the moment I only send strings but I would like to be able to send image and PDF to the client.

Hope those explaination are more clear now...
 
Upvote 0

Yannick Proulx

Member
Licensed User
well I guess I'm a bit confused about those networking things ...
sorry for my error. I'm out of my confort zone with those network stuff.
does this method allow multiple connection at the same time? I mean multiple client connected to the server and requesting stuff
also, will it work over internet?

once again, Thank you very much for your fast support

Yannick
 
Last edited:
Upvote 0

Yannick Proulx

Member
Licensed User
ok I'll try to explain my project

I would like to have a bi-directional communication between my .net server and mutliple B4A client requesting different kind of data.
i would like to keep my server in .net as a huge part of it will be reusable. Only the communication protocol will change
I want my server to be accessible over internet so my selling team will be able to query the server where ever they are.

My B4a client will request data to the server and wait for the server to reply the data.

the type of data I wanna transfer is :
-string
-json
-pdf
-jpg
-png
-zip

as I said, I already have a MQTT (B4A client / .net server) version which is only working locally and with string and json.I know I could use a service like CloudMQTT to get internet communication but I would like to transfer files which I don'T think is possible over MQTT.
Another thing, as MQTT is not directly connected to client/server, so I need to ping the server offently to be sure it is listening.

I hope you understand more clearly what I'm trying to do

thank you
Yannick
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
Don't use raw sockets for this.

Are you sure that you need bi-directional communication? Standard http is made of http requests being sent from the client to the server and then the server respond to the client. This is the simplest option and it powers 99% of the internet.

If you want to allow the server to send information to the client without a client request then you can use WebSockets.

You can use B4J to quickly build a http + WebSockets server. Later you can switch to .Net if you like.
 
Upvote 0

Yannick Proulx

Member
Licensed User
erel,
could you show me an exemple of how the server (B4J) can reply with a file, in exemple a JPG
the resp.write only allow to send string.

and how the client (B4A) will get this file

I guess it will be in the inputstream of the jobdone sub but I'm not totally sure

thank for your help!
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…