network example

rls456

Member
Licensed User
Longtime User
using the network example on the desktop and android device. I can get them to connect but when it comes to reading the file from the desktop it does not read the filename and operation fails.
This is the line of code in Network android example line 79

fileName = BytesToString(buffer, 0, strLen, "UTF-8") 'convert the bytes to string lblName.Text = "File Name: " & fileName
 

rls456

Member
Licensed User
Longtime User
send code

How are you sending the string?
here is the code and i am using wirless connection


tmrWaitForData.Enabled = False
binary1.New1(Client.GetStream,False)
binary1.WriteByte(0) 'Signal to the other computer that sending has started.
If OpenDialog1.Show = cCancel Then
binary1.WriteInt64(0) 'Send a cancel signal.
tmrWaitForData.Enabled = True
Return
End If
lblFile.Text = OpenDialog1.File
FileOpen(c1,OpenDialog1.File,cRandom)
fileStream.New1(c1,False)
size = fileStream.Length
binary1.WriteInt64(size) 'Send the file size.
binary1.WriteString(FileName(OpenDialog1.File)) 'Send the file name.
count = fileStream.ReadBytes(buffer(),8192) 'Read from the file stream.
Do While count > 0
binary1.WriteBytes2(buffer(),0,count) 'Write to the network stream.
size = size - count
count = fileStream.ReadBytes(buffer(),8192)
label1.Text = size & " bytes left."
DoEvents
Loop
FileClose(c1)
label1.Text = "File transfer completed."
' tmrWaitForData.Enabled = True
 
Upvote 0

rls456

Member
Licensed User
Longtime User
The problem is here:
B4X:
binary1.WriteString
This call uses .Net standard protocol for sending strings. It first sends the string length and then the string. It is only useful for sending strings to other .Net applications.
You should instead convert the string to bytes and then send the bytes.

if I convert the string to bytes will it still work in net enviroment
I am trying to write to ppc and android from the desktop
Thanks
 
Upvote 0
Top