Problem with send through network

dibesw

Active Member
Licensed User
Longtime User
I want send one text file from device to desktop through the network.

I have this program that receive text file under Basic4PPC and works well:
B4X:
Sub tmrWaitForData_Tick 'Checks the DataAvailable property
'If data is available then the other computer is sending a file.
   If Client.DataAvailable = True Then
      tmrWaitForData.Enabled = False
      binary1.New1(Client.GetStream,False)
      binary1.ReadByte 'Read the first byte
      size = binary1.ReadInt64 'The size of the file.
      If size = 0 Then 'The user pressed cancel.
         tmrWaitForData.Enabled = True
         Return
      End If
      name = binary1.ReadString 'The name of the file.
      name = "text.txt" 'The name of the file.
      size=10
      label1.Text = "Receiving " & name & " Size: " & size
      If FileExist(name) = True Then FileDel(name)
      FileOpen(c1,name,cRandom)
      fileStream.New1(c1,False)
      Do Until size = 0
         count = binary1.ReadBytes(buffer(),8192)
                        ..................
This code read:

. first byte
. size of the file
. name of the file
. the file

Now i am trying to send one txt file from the android device to desktop but only this code not works:
B4X:
Sub Process_Globals
   Dim Socket1 As Socket
End Sub

Sub Activity_Create(FirstTime As Boolean)
    Socket1.Initialize("Socket1")
    Socket1.Connect("192.168.1.10" , 5007, 20000)
    Activity.LoadLayout("1")
    ToastMessageShow("Connected", True)
End Sub

Sub SendData
   Dim In As InputStream 

   IN = File.OpenInput(File.DirRootExternal, "test.txt")
   File.Copy2(IN, socket1.OutputStream)
End Sub
Please can someone help me?
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
This code read:

. first byte
. size of the file
. name of the file
. the file
Your B4A code only sends the file. Where are the first three values?

Basic4ppc (actually .Net) ReadString expects a specific format. You will not be able to use it when reading from Android.

I recommend you to try B4AServer. It will make things simpler and more reliable: http://www.b4x.com/forum/showthread.php?p=53629
 
Upvote 0

dibesw

Active Member
Licensed User
Longtime User
This is the problem for me.
I can't find how what are the first three instructions for send the first three values.
 
Upvote 0
Top