B4J Question [solved] Send message pc to mobile phone

ivanomonti

Expert
Licensed User
Longtime User
how can I connect a mobile device via usb cable or wifi without necessarily having servers or similar. I would like to send messages through the messaging apps installed on my phone
 

Star-Dust

Expert
Licensed User
Longtime User
Send messages over the network with udp packets in broadcast. You won't need servers and all devices listening on the specific port will get the message.

Then if you want you can add a protocol, an encryption to make the messages unreadable to third parties
 
Upvote 0

Star-Dust

Expert
Licensed User
Longtime User
Yes, I've done something similar before. As soon as I can, I'll attach an example
 
Upvote 0

peacemaker

Expert
Licensed User
Longtime User
 
Upvote 0

Star-Dust

Expert
Licensed User
Longtime User
Here is an example of cross-platform device communication over UDP.
The example simulates a chat, but you can send data Bytes, Images etc... by establishing a small protocol.
Then if you do an encryption you protect it from prying eyes

Works if all devices are in the same subnet.
 

Attachments

  • SenderNoServer.zip
    15.2 KB · Views: 208
Upvote 0

ivanomonti

Expert
Licensed User
Longtime User
quindi devo avere due app come il tuo esempio su due dispositivi diversi, nella stessa rete (home ad esempio) e cio che scrivo nel primo campo viene letto dall'altro pc che sta in ascolto, giusto...

so I have to have two apps like your example on two different devices, in the same network (home for example) and what I write in the first field is read by the other pc that is listening, right...
 
Upvote 0

Star-Dust

Expert
Licensed User
Longtime User
@Star-Dust è possibile anche qui avere la lista di chi è connesso

@Star-Dust it is also possible here to have the list of who is connected
Yes right, put two devices (two or more devices, windows, android, iphone doesn't matter) and one writes and the others receive.

You can also have a list but you have to create a transmission protocol and you can have a list, send files, even audio communication .... anything you like ... see also this example

 
Upvote 0

ivanomonti

Expert
Licensed User
Longtime User
Yes right, put two devices (two or more devices, windows, android, iphone doesn't matter) and one writes and the others receive.

You can also have a list but you have to create a transmission protocol and you can have a list, send files, even audio communication .... anything you like ... see also this example

@Star-Dust but that's only for the local network, if you wanted to go outside everything changes
 
Upvote 0

Star-Dust

Expert
Licensed User
Longtime User
Yes, on the internal network as I wrote. I proposed this because I didn't see it specified that an external-network transmission was needed.

If this is your requirement then a server is needed at least to broadcast the ip address of the devices that need to communicate.
 
Upvote 0

ivanomonti

Expert
Licensed User
Longtime User
Sì, sulla rete interna come ho scritto. L'ho proposto perché non ho visto specificato che era necessaria una trasmissione di rete esterna.

Se questo è il tuo requisito, è necessario almeno un server per trasmettere l'indirizzo IP dei dispositivi che devono comunicare.
@Star-Dust unless I have a static ip address or use what was once noip

1679085466584.png
 
Last edited:
Upvote 0

Star-Dust

Expert
Licensed User
Longtime User
noip is a server to share ip address.
Having a static io helps if it's a public ip and allows access from outside.

I hope my code was helpful to you
 
Upvote 0

M.LAZ

Active Member
Licensed User
Longtime User
Hi @Star-Dust
For a long time in this forum i asked a lot about this example but using tcp/ip protocol . I didn't find help or any sample example ..
I need just a small example to send multi msgs from clients to main server (pc) using tcp on wifi network.

1. Server receive a msg from any connected client and reply with a any text msg to the same client.
2. Make a list with a connected clients with thier ip address.
3. Remove any disconnected clients from the list.
That's all..

Thanks a lot for every one who help me and i will appreciate your time.
 
Upvote 0

Star-Dust

Expert
Licensed User
Longtime User
it's always best to open a new thread for each new question.

There are many of examples on the forum, maybe you're wrong with your search terms.

This example I'm attaching broadcasts an audio stream, but you can change it to broadcast text. But if you search the forum you will surely find what you need

 
Upvote 0

M.LAZ

Active Member
Licensed User
Longtime User
i did it one b4j as server and multi b4a clients

but when server need to send data to a certain client or device ,i use this code and send the same data to all clients or devices
how to send data to a certain device?


B4X:
SendData (ser.ConvertObjectToBytes(xx))


Private Sub SendData (data() As Byte)
    If connected Then astream.Write(data)
End Sub
 
Upvote 0

Star-Dust

Expert
Licensed User
Longtime User
You have to modify the code to send to a specific IP address or create some sort of protocol that communicates to the server if the transmission is addressed to all at an address. In any case you need to know the address of the device
 
Upvote 0
Top