0

I'm having this incredibly crazy error! I drop idhttpserver,webbrowser on a new mobile android app.

I want the server to provide content to the browser. It works great on windows but fails on my android device. I tested a tcpserver and tcpclient. I can get the client to connect, but when I start writeln and readln I get segmentation fault.

Even if I run with debugging off the application still crashes... here is the code snippet.

procedure TForm37.Button1Click(Sender: TObject);
begin
  IdHTTPServer1.Bindings.Add;
  try
    IdHTTPServer1.Active := true; 
    if IdHTTPServer1.Active then
      Button1.Text := 'Server Started';
  except on E: Exception do
    Button1.Text := 'Server Failed';
  end;
end;

procedure TForm37.Button2Click(Sender: TObject);
var
  astring : string;
begin
  try
    astring := IdHTTP1.Get('http://10.0.1.78:6000/');
    // or  astring := IdHTTP1.Get('http://127.0.0.1:6000/');
    ShowMessage(astring);
  except on E: Exception do
    Button2.Text := 'connection failed';
  end;
end;

procedure TForm37.IdHTTPServer1CommandGet(AContext: TIdContext;
  ARequestInfo: TIdHTTPRequestInfo; AResponseInfo: TIdHTTPResponseInfo);
begin
  AResponseInfo.ContentText := 
    '<html><head><title>My First Response</title></head>' +
    '<body>Command: ' + ARequestInfo.Command +
    '<br />Host: ' + ARequestInfo.Host +
    '<br />URI: ' + ARequestInfo.URI +
    '<br />UserAgent: ' + ARequestInfo.UserAgent +
    '</body></html>';
end;
Johan
  • 74,508
  • 24
  • 191
  • 319
Skywalker
  • 23
  • 1
  • 7
  • `Bindings.Add` simply creates a new binding to IP 0.0.0.0, port 80. Neither of those relates to the IP or port you're trying to access. You should configure the binding after adding it. – Ken White Oct 04 '13 at 17:41
  • More accurately, `Bindings.Add` creates a new binding that defaults to the `TIdCustomTCPServer.DefaultPort` property value, which just happens to default to 80 in `TIdHTTPServer` but can be changed. Skywalker could have set the `DefaultPort` to 6000 before calling `Bindings.Add`. – Remy Lebeau Oct 05 '13 at 00:33
  • @Skywalker: please indicate which line of code is actually raising the error, and provide the complete error message. A Segmentation Fault is the equivalent of an AccessViolation on Windows platforms. Which likely means that something was not initialized correctly before you tried to use it. – Remy Lebeau Oct 05 '13 at 00:36
  • @KenWhite I did set the default port to 6000 when i call bindings.add; it adds the binding `0.0.0.0:6000` and I have tried local loop and my devices IP address. connecting to the `idhttpserver` is not the problem. – Skywalker Oct 06 '13 at 08:08
  • @RemyLebeau This is just the thing I'm finding it very hard to break into the code that actually creates the problem in the `idhttpserver` but my test that I ran with `idtcpserver` and `idtcpclient` by just connecting and then calling `idtcpclient.writeln('hi');` and on `idtcpserver.Onexecute` event i put `acontext.connection.socket.readln(avar);` I have done this a million times on windows with little chat apps and file sharing. I'm very confused ! I know in lazarus you had to add `cthreads` to the uses clause to make indy work but I don't think its the same problem here. Thanks ! – Skywalker Oct 06 '13 at 08:09
  • @Skywalker: I don't have XE5 installed yet, so I can't debug this myself. Offhand, I don't see anything wrong with your code, so this might be a problem with either the XE5 RTL or Indy's Android stack. Hard to say without seeing the call stack leading up to the error. – Remy Lebeau Oct 06 '13 at 16:59
  • @RemyLebeau Thank you, I'll try and get as much debug info for you but I'm almost certain it has to do with Indy. – Skywalker Oct 07 '13 at 06:34
  • @RemyLebeau this is the CPU break point `743F7DFC 45EA0921 orr.w r1, r5, r9, lsl #8` and this is the call stack `:743F7DFC System.Classes.TStreamer.writeline(unsigned long long)` . I don't know if this helps you but this is as far as it goes. – Skywalker Oct 07 '13 at 09:59
  • @Skywalker: Those instructions have absolutely nothing to do with Indy at all. There is no `TStreamer` class in the `System.Classes` unit, maybe you meant `TStreamWriter` instead? Either way, Indy does not have any `WriteLine()` methods. There is a `TIdIOHandler.WriteLn()` method, which is what you should be calling instead: `IdTCPClient.IOHandler.WriteLn('hi');` – Remy Lebeau Oct 07 '13 at 17:58
  • @RemyLebeau noted. Then I have no idea whats the problem ... – Skywalker Oct 08 '13 at 06:22
  • @RemyLebeau: Hi, RemyLebeau, I did some test codes for IdHTTPServer with Android, and something is very strange. In Android environment, the form will become out of control when IdHTTPServer is activated. I reduced the MaxConnection to 1, ListenQueu to 1, and fiinally the IdHTTPServer does not cause app crashed. I did modify TIdDNSResolver, and created TIdDNSServer, so maybe I can do something about this situation. Besides, one of my urgent project requires this feature to be completed.... – Dennies Chang Nov 28 '13 at 22:29
  • @DenniesChang: what goes "out of control" exactly? Please be more specific. – Remy Lebeau Nov 29 '13 at 04:23
  • @RemyLebeau: The situation "out of control", means all components shown in the form does not response anymore. e.g., One button was placed on right-top corner, if the server was not activated, the button can response event. If server was activated, the button cannot response anymore. I can see that server components (I tried TIdHTTPServer, TIdTCPServer, and TIdTCPCmdServer) bring up 2-3 new threads, and the threads hand up, Delphi show the thread start with black color. I run the same code in Win32, the threads show with blue color, and the threads exit very soon. In Android, they don't. – Dennies Chang Nov 29 '13 at 06:38
  • @DenniesChange: that sounds like the server is doing something that is not thread-safe and is blocking the main thread from processing new messages. Given the code you have shown, I don't see how that could be happening. And I don't know what you mean by "start with black color". – Remy Lebeau Nov 29 '13 at 15:57

1 Answers1

0

This answer is sure to be very unpopular. I too am trying to develop an FM HD Android Datasnap application using XE5 and I am getting Segementation Fault (11) at every turn! It's completely unpredictable. Compiling as a Win32 target produces no errors. For example: A button's event handler will execute and complete successfully the first time the button is clicked and then on a second click it will produce a segmentation fault for no apparent reason. My application almost does nothing useful at this point, but it's taken me hours and hours of trial an error to get it to do what it does. I personally don't think that Android development in Delphi XE5 is actually viable unless you happen to be someone who already develops Android apps using the other dev. environments and/or you've got nothing better to do all day than fight with it.

Freddie bell
  • 192
  • 1
  • 8
  • I'm actively developing an Android app it works really well... Most problems occur cause we are so use to the way win32 handles freeing of memory and how components are created i find that FMX is still very bugy in some errors but super awesom in other areas. Maybe post some code to me and Ill see if I can help you ? Have a great Day Mike ! – Skywalker Nov 21 '13 at 06:32