Android Question receiving objects from client on android http server

MbedAndroid

Well-Known Member
Licensed User
Longtime User
i'm puzzling with the request of the http server https://www.b4x.com/android/forum/threads/embed-an-http-server-in-your-android-application.25984/

same program in b4j uses this input stream
B4X:
Sub ReadObject (In As InputStream) As Object
  Dim out As OutputStream
  out.InitializeToBytesArray(0)
  File.Copy2(In, out)
  Dim raf2 As RandomAccessFile
  raf2.Initialize3(out.ToBytesArray, False)
  Dim res As Object = raf2.ReadObject(0)
  Log(raf2.CurrentPosition)
  raf2.Close
  Return res
End Sub
how to fix this on android?
i tried this example, but failed
B4X:
  Dim upload As String = Request.GetUploadedFile("order")
   File.Copy(server.TempFolder, upload, CurrentPath, Request.GetParameter("order"))
   File.Copy(server.TempFolder, upload, File.DirRootExternal & "/" & bestanden.filedir, "1.dat") 'the file name is sent as a parameter
   File.Delete(server.TempFolder, upload) 'delete the temporary file.

Sending a object back to the client android was no problem
B4X:
Sub sendobject(obj As Object, out As ServletResponse)

   Dim raf As RandomAccessFile
   raf.Initialize(File.DirRootExternal & "/" & bestanden.filedir, "1.dat", False)
   raf.WriteObject(obj, True, 0)

   out.SetContentType("application")
   out.SendFile(File.DirRootExternal & "/" & bestanden.filedir, "1.dat")
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
same program in b4j uses this input stream
There are simpler solutions available now with B4XSerializator.
No need to create a temporary file.

I wouldn't use the HttpServer library unless you want to use a browser as the client. There are simpler and better options for custom solutions.
 
Upvote 0
Top