Chat PC - Android

diversity

Member
Licensed User
Longtime User
Hey B4A community,
in the last 4 days i've try to make a simple network (chat) appilcation which should allow me to send little text messages from Android-Phone <-> Computer.

I've try to make it with the networklib but i don't get it, how it will work.
(I can't use Bluetooth because me pc has no features for it :sign0161: )

I've scripted a little .NET Application in VB2010 which contains all connected devices in a list, listen to all connected devices on port 9092 and send a re-mail to everyone if it get an.
Thats works fine (tested: connect from my laptop or other pc to the server.)

But now is the question how to connect and send messages from my phone to the 'server'-application on my pc. I've readed some threads and the Tutorials about the Network.lib but i don't get it.

I'll be happy about your answers and hope you can help me to learn more about it.

Best regards
Diversity

By the way: At the beginn i wanna make the app for my local network, later maybe for the worldwideweb ^^
 

Spinter

Active Member
Licensed User
Longtime User
Sample Client!

Librery:
Core
Network
RandomAccessFile
'Activity module

Sub Process_Globals
Dim AStreams As AsyncStreams
Dim Server As ServerSocket
Dim Socket1 As Socket
Dim port As String
Dim ServerIp As String



End Sub
Sub Globals

Dim Button1 As Button
Dim Button2 As Button
End Sub

Sub Activity_Create(FirstTime As Boolean)
Activity.LoadLayout("1")


port = 2345
ServerIp="YouIpSERVER"

End Sub



Sub connet
Try
Socket1.Initialize("Socket1")
Socket1.Connect(ServerIp ,port, 20000)
Catch
ToastMessageShow( "Non conesso", True)
End Try
End Sub


Sub Socket1_Connected (Connected As Boolean)
If Connected = True Then
ToastMessageShow( "Connesso", True)
AStreams.Initialize(Socket1.InputStream,Socket1.OutputStream,"Astreams")
End If
End Sub

Sub send_data(data As String)

If AStreams.IsInitialized = True Then
Dim buffer() As Byte
data=data
buffer = data.GetBytes("UTF8")
AStreams.Write(buffer)
End If
End Sub

Sub AStreams_NewData (Buffer() As Byte)
Dim msg As String
msg = BytesToString(Buffer, 0, Buffer.Length, "UTF8")
ToastMessageShow( msg, True)
End Sub

Sub AStreams_Error
ToastMessageShow( LastException.Message, True)
End Sub

Sub Button1_Click
connet
End Sub
Sub Button2_Click
send_data("hello!")
End Sub
 
Last edited:
Upvote 0

diversity

Member
Licensed User
Longtime User
hey guys
first: thanks for the fast answers

My code was correctly, i've got a wrong (older or something like that) version of the libary and missed one features i've saw in a chat example from the forum.

Now everything is working fine i only 3-4 'spaces' at the begin of the text but i'll work on it

thanks
 
Upvote 0
Top