Receive Only one character over client socket!! ?

pikthai2004

Member
Licensed User
Longtime User
Hi Everyone,

I try to test send /receive data over socket but Why Receive Only one character over client socket!! ?

Android device as client ,PC as server.

Server can received all data from client,But when server send data ,client received only one character, Like this
Android =>send "Hello Server"
Server <= receive "Hello Server"
Server => send "Hello Client"
Android <= receive "H"

I use a AsyncStreams and receive data in AStreams_NewData like this

Sub AStreams_NewData (Buffer() As Byte)
Dim msg As String
msg = BytesToString(Buffer, 0, Buffer.Length, "ISO-8859-1")
EditText1.Text = msg
Log(msg)
End Sub


Thank you very much.
 

rbsoft

Active Member
Licensed User
Longtime User
This is - I think - normal behavior.

When I send data from my pc server applications to Android or WindowsMobile applications they always receive first just one byte and afterwards the the rest of the data comes in. I think probably one byte is sent first to test the connection before the whole message is sent.

You need to collect the whole message in a global variable.

Rolf
 
Upvote 0

KashMalaga

Member
Licensed User
Longtime User

+1
 
Upvote 0

wl

Well-Known Member
Licensed User
Longtime User
I think not.

I did some tests myself sending data from a .NET socket server to an app.

The Buffer() byte array of the NewData in event fact contained all characters (in fact all characters I sent at once by the .NET socket server)

Wim
 
Upvote 0

pikthai2004

Member
Licensed User
Longtime User
Thank you everyone. I am a newbie.

I Changed my code from
B4X:
AStreams.InitializePrefix(Socket1.InputStream, False, Socket1.OutputStream, "AStreams")

to

B4X:
AStreams.Initialize(Socket1.InputStream, Socket1.OutputStream, "AStreams")

OK it work.
 
Upvote 0

wl

Well-Known Member
Licensed User
Longtime User
ok, this explains a lot ...

When using the syntax with the prefix you should follow the convention that the first few bytes (don't recall the amount by heart) indicate the length of the message that will follow: in this case you should adapt the server sending the data accordingly.

You now changed it in the more "standard" way: just reading all data received, which I also used...
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…