Android Question how to write a http server listen on a port?by httpjob ?

hears

Active Member
Licensed User
Longtime User
here have a http server libary in forum,
but i cannot use it ,because ,i need get SOAP xml in the post.
if i use httpjob, it must firt post to a server. but in my app , android is a server, alway waiting client connect, data in soap xml format .
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
Upvote 0

drgottjr

Expert
Licensed User
Longtime User
my understanding is that you want to post to a server that is expecting soap, yes? if yes, then see erel's post here
 
Upvote 0

OliverA

Expert
Licensed User
Longtime User
my understanding is that you want to post to a server that is expecting soap, yes
I think poster is trying to write a server that runs on android and receives SOAP post requests
 
Upvote 0

hears

Active Member
Licensed User
Longtime User
Upvote 0

hears

Active Member
Licensed User
Longtime User
Okhttp will not help here. You need to use ServerSocket.
It is quite simple to build a minimal http server. A small server is hidden in the B4J implementation of Google OAuth: https://www.b4x.com/android/forum/threads/class-b4x-google-oauth2.79426/#content

Two more robust server implementations: [B4X] [class] MJPEG decoder
And: [B4X] FTP Server implemented with Socket and AsyncStreams

thanks for reply ,i have write a server app by ServerSocket ,but cannot work as a http server now ,i guess here is a litte wrong...because APP cannot pring Helloworld in a browse client.


B4X:
Sub Activity_Create(FirstTime As Boolean)
    Activity.LoadLayout("1")
    If FirstTime Then
        server.Initialize(5000, "server")
        Log(server.GetMyWifiIP)
        lblState.Text=server.GetMyWifiIP
        server.Listen
    End If
End Sub

Sub server_NewConnection (Successful As Boolean, NewSocket As Socket)
    If Successful Then
        If ast.IsInitialized Then ast.Close
        ast.Initialize( Me, "ast", NewSocket.InputStream, NewSocket.OutputStream) 'initialize AsyncStreamsText with the socket streams.
    Else
        Log(LastException)
    End If
    server.Listen
End Sub

Sub ast_NewText(Text As String)
    Log("Text: " & Text)
    Log(Text.Length)
   

   
    Dim information As StringBuilder
    information.Initialize
    information.Append("HTTP/1.1 200 OK")
    information.Append("Date: Sat, 18 Apr 2020 13:41:56 GMT")
    information.Append("server: App-webs/")
    information.Append("Connection: close")
    information.Append("Content-Length: 5951")
    information.Append("Content-Type: Application/soap+xml; charset=utf-8")
   
   

   
    If (Text.Contains("Host"))Then
        ast.Write("HTTP/1.1 200 OK "& Chr(10) & Chr(13))
        ast.Write("Date: Sat, 18 Apr 2020 13:41:56 GMT")
        ast.Write("server: App-webs/")
        ast.Write("Connection: close")
        ast.Write("Content-Length: 500")
        ast.Write("Content-Type:"&" text/html;charset=utf-8"&Chr(10) & Chr(13))
       
        ast.Write("<html>helloword<html>"&Chr(10) & Chr(13))
       
        Log("GET INFO")
       
    End If
    End Sub
 
Last edited:
Upvote 0

hears

Active Member
Licensed User
Longtime User
this server APP cannot pring Helloworld in a browse client now.
 

Attachments

  • httpSERVER.zip
    8.9 KB · Views: 133
Upvote 0

hears

Active Member
Licensed User
Longtime User
Okhttp will not help here. You need to use ServerSocket.
It is quite simple to build a minimal http server. A small server is hidden in the B4J implementation of Google OAuth: https://www.b4x.com/android/forum/threads/class-b4x-google-oauth2.79426/#content

Two more robust server implementations: [B4X] [class] MJPEG decoder
And: [B4X] FTP Server implemented with Socket and AsyncStreams


B4X:
    ast.Write("HTTP/1.1 200 OK\r\n"&CRLF)
    ast.Write("Content-Type: text/html"&CRLF&CRLF)
    ast.Write("<!DOCTYPE HTML>"&CRLF&"<html"&CRLF&"><body>"&CRLF)
    ast.Write("Welcome to ProPV<br>"&CRLF)
    ast.Write("login "&CRLF)
    ast.write("</body></html> "&CRLF)


thanks for help .
after i change to CRLF , and before <html>must have 2 CRLF ,it is working now
 
Upvote 0
Top